Edit report at http://bugs.php.net/bug.php?id=53651&edit=1
ID: 53651 Updated by: and...@php.net Reported by: marc at phpmyadmin dot net Summary: Under mysqlnd, mysqli_affected_rows() returns 0 -Status: Assigned +Status: Feedback Type: Bug Package: MySQLi related Operating System: Linux PHP Version: 5.3.4 Assigned To: mysql Block user comment: N Private report: N New Comment: I can't reproduce it. Maybe it's bogus due to something else. Here are my results : myslqnd + MySQL 5.5.8 (executed twice in a row) and...@poohie:/work/vanilla/php/php-src/branches/PHP_5_3$ ./php b.php Affected rows (UPDATE): 1 and...@poohie:/work/vanilla/php/php-src/branches/PHP_5_3$ ./php b.php Affected rows (UPDATE): 0 myslqnd + MySQL 5.1-dev (executed twice in a row) and...@poohie:/work/vanilla/php/php-src/branches/PHP_5_3$ ./php b.php Affected rows (UPDATE): 1 and...@poohie:/work/vanilla/php/php-src/branches/PHP_5_3$ ./php b.php Affected rows (UPDATE): 0 As you see, the second time the result is 0. Why? It is a feature or gotcha of MySQL. If the row doesn't change affected_rows is 0. And the row doesn't change from toto to toto there is no change, thus the row is left intact. Previous Comments: ------------------------------------------------------------------------ [2011-01-04 19:08:06] marc at phpmyadmin dot net Description: ------------ In PHP 5.3.4 (also 5.3.3 and 5.3.2), connecting to MySQL 5.1.49 with mysqli extension under mysqlnd, I always obtain 0 as the result of mysqli_affected_rows() following an UPDATE that changed one row. Works fine under PHP 5.2.14 + MySQL 5.1.49 client library. Thanks, Marc Delisle Test script: --------------- <?php $link = mysqli_init(); mysqli_real_connect($link, 'localhost', 'user', 'password', 'db'); /* * CREATE TABLE mytable (id int not null, myname varchar(50 not null)) engine=MyISAM; * INSERT INTO mytable (id, myname) values(1, 'toto'); */ mysqli_query($link, "update mytable set myname='Marc' where id=1"); printf("Affected rows (UPDATE): %d\n", mysqli_affected_rows($link)); mysqli_close($link); ?> Expected result: ---------------- Affected rows (UPDATE): 1 Actual result: -------------- Affected rows (UPDATE): 0 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=53651&edit=1