[wp-trac] [WordPress Trac] #44163: wpdb->update() fails, showing no error message
WordPress Trac
noreply at wordpress.org
Sun May 20 18:54:05 UTC 2018
#44163: wpdb->update() fails, showing no error message
--------------------------+-----------------------------
Reporter: tazotodua | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
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
<?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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44163>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list