Opened 6 years ago
Last modified 6 years ago
#44163 new defect (bug)
wpdb->update() fails, showing no error message
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | 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 (4)
#3
in reply to:
↑ 2
@
6 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.
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.