Opened 7 years ago
Closed 7 months ago
#44163 closed defect (bug) (duplicate)
wpdb->update() fails, showing no error message
Reported by: | tazotodua | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Database | Keywords: | reporter-feedback |
Focuses: | Cc: |
Description
It's my second report about the incompletness of wpdb->update function.
1-2 years ago I've reported the scenario when it failed to update, but last_error
was empty.
Now, another scenario, when it fails , but last_error
is empty, is the following:
i.e. create a table with "NOT NULL"
<?php $x= $wpdb->query("CREATE TABLE IF NOT EXISTS `example_table` ( `rowID` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(150) NOT NULL, `id` varchar(150) NOT NULL, `data` LONGTEXT NOT NULL DEFAULT '', PRIMARY KEY (`rowID`), UNIQUE KEY `rowID` (`rowID`) ) ". $wpdb->get_charset_collate() ." AUTO_INCREMENT=1;" );
then insert some empty value:
$wpdb->insert("example_table", array("name" => "James", "id"=>"123", "data"=>"blabla") );
then try to update
$wpdb->update("example_table", array("name"=>"Jonathan"), array("id"=>"133") );
it doesnt update.
I have dumped $this->dbh
(in wp-db.php 1887 line), and it shows affected lines: 0
last_error
is empty. After spending much time, found that I was missing "required" parameter and added
$wpdb->update("example_table", array("name"=>"Jonathan", "data"=>"new-blabla"), array("id"=>"133") );
("NOT NULL" requirement caused failure)
so, it's good, last_error contained some information, when affected lines are 0, or like such scenarios.
Change History (5)
#3
in reply to:
↑ 2
@
7 years ago
sorry, yeah, 133 was typo. There seems problem on my side.
However, my main concert is that there are cases, when update
fails, but last_error
is empty. That's what I wished to be solved. in wp-db.php
in update function, there are cases like that, when last_error is not being set, but returning false.
#4
@
7 years ago
Thank you for your feedback.
Would you mind getting back to me with a specific example so that I can reproduce the issue and look deeper into it?
#5
@
7 months ago
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
Related to #32315.
[52176] populated the wpdb::$last_error
(instead of silently failing) when data is invalid or too long. It modified the wpdb::process_fields()
logic which is also used by wpdb::update()
. In testing an insert and update, it is recording the error message in wpdb::$last_error
. I suspect this changeset also resolved this ticket.
Given there's been no follow-up, I'll mark it as a duplicate of #32315. However, if the problem persists, please provide step-by-step instructions of how to reproduce and reopen the ticket. Thank you.
Your insert code is:
and Update code is:
Not sure if you have used different
id
intentionally in insert and update. I think it should be 123!I tested with the following and worked perfectly for me.