php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53651 Under mysqlnd, mysqli_affected_rows() returns 0
Submitted: 2011-01-04 19:08 UTC Modified: 2011-01-05 13:59 UTC
From: marc at phpmyadmin dot net Assigned: mysql (profile)
Status: Closed Package: MySQLi related
PHP Version: 5.3.4 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: marc at phpmyadmin dot net
New email:
PHP Version: OS:

 

 [2011-01-04 19:08 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-05 10:15 UTC] uw@php.net
-Assigned To: +Assigned To: mysql
 [2011-01-05 10:31 UTC] andrey@php.net
-Status: Assigned +Status: Feedback
 [2011-01-05 10:31 UTC] andrey@php.net
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)

andrey@poohie:/work/vanilla/php/php-src/branches/PHP_5_3$ ./php b.php
Affected rows (UPDATE): 1
andrey@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)
andrey@poohie:/work/vanilla/php/php-src/branches/PHP_5_3$ ./php b.php
Affected rows (UPDATE): 1
andrey@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.
 [2011-01-05 12:00 UTC] marc at phpmyadmin dot net
-Status: Feedback +Status: Assigned
 [2011-01-05 12:00 UTC] marc at phpmyadmin dot net
Hi Andrey,
here is my configuration, maybe the presence of PDO has an impact?

./configure --with-apxs2=/usr/local/apache2/bin/apxs \
        --with-libdir=lib64 \
        --disable-debug \
        --enable-calendar \
        --with-gd=shared \
        --with-freetype-dir \
        --with-mysql=shared,mysqlnd \
        --with-mysqli=shared,mysqlnd \
        --with-regex=php \
        --with-png-dir=/usr/lib \
        --with-zlib=shared \
        --with-iconv=shared \
        --enable-ftp \
        --with-mcrypt=shared \
        --with-bz2=shared \
        --enable-zip \
        --with-jpeg-dir=/usr/lib \
        --enable-mbstring \
        --without-sqlite \
        --enable-dom \
        --enable-json \
        --enable-pdo=shared \
        --with-pdo-mysql=shared,mysqlnd \
        --without-pdo-sqlite \
        --with-pear \
        --enable-spl \
        --enable-bcmath \
        --with-curl=shared \
        --with-ldap=shared,/usr \
        --with-gettext=shared \
        --with-snmp=shared \
        --enable-sockets
 [2011-01-05 12:08 UTC] andrey@php.net
-Status: Assigned +Status: Feedback
 [2011-01-05 12:08 UTC] andrey@php.net
Can you post output from the script with freshly created table and freshly inserted row. Please, run the script twice. Thanks!
 [2011-01-05 12:28 UTC] marc at phpmyadmin dot net
-Status: Feedback +Status: Assigned
 [2011-01-05 12:28 UTC] marc at phpmyadmin dot net
Andrey,
I had a permission problem at MySQL level that produced the "0" output. Now I can no longer reproduce the problem with the test script, but I still have this problem in phpMyAdmin. I'll try to come up with a new test script.
 [2011-01-05 13:34 UTC] uw@php.net
No, neither adding PDO nor the moon phase can impact it.
 [2011-01-05 13:59 UTC] marc at phpmyadmin dot net
-Status: Assigned +Status: Closed
 [2011-01-05 13:59 UTC] marc at phpmyadmin dot net
Sorry for the disturbance.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 15:01:36 2025 UTC