Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This error on following modules
search
users
update
statistics
bootstrap.inc
cache.inc
lock.inc
db_affected_rows return
0 if there is no update. mean everything is same in update query.
eg: update node set status=1 where nid=1;
-1 if record does n't exists.
eg: update node set status=1 where nid=-9;
check db_affected_rows function
http://api.drupal.org/api/drupal/includes%21database.mysqli.inc/function...
it call following php function
http://php.net/manual/en/mysqli.affected-rows.php
if (!db_affected_rows()) {
}
must be
if (db_affected_rows() == -1) {
}
Comments
Comment #1
lalit774 CreditAttribution: lalit774 commentedif i have run following code in a test file in drupal 6 root. i will get same result every time. db_affected_rows() return 1 result every time. if i have change node table name to non existing table like node_#$#$. Then db_affected_rows() also give me 1 result.
Comment #2
mdupontYou get 1 result when specifying a non-existing table because of #195812 . When there is an error during db_query() and that you have dblog enabled, there will be an error message written to the DB, and the "1" you see is because the write of the error message is successful. Silly design bug.
Comment #3
mdupontI don't see any bug here, referring to the mysqli documentation:
It says that -1 is returned only when there is an error in the query. Trying to UPDATE a row that doesn't exist is not a query error, and it returns that 0 rows were affected.
When I run
db_query("UPDATE {node} SET status = 1 WHERE node = 1");
on a site that has no node 1, db_affected_rows() returns 0 as expected. If it wouldn't work that way a large set of core modules would have been severely broken.Comment #4
lalit774 CreditAttribution: lalit774 commentedThere is a bug in MySQL.
Please see below.
http://bugs.mysql.com/bug.php?id=29157
http://drupal.org/node/805858
Comment #4.0
lalit774 CreditAttribution: lalit774 commentedmissing code brace