From: Operating system: all PHP version: 5.4SVN-2011-09-05 (SVN) Package: MySQLi related Bug Type: Bug Bug description:mysqli_num_rows() returns always 0 for unbuffered, when mysqlnd is used
Description: ------------ As the description says, there is wrong check in mysqli, which doesn't allow the mysqlnd code to run. mysqli returns always 0 for num_rows() even if the whole result set has been read. This bug exists since 5.3.0, which first bundled mysqli with mysqlnd. Test script: --------------- ./php -r '$c=mysqli_connect("127.0.0.1","root","root","test");var_dump($c->real_query("SELECT 1"));var_dump($res=$c->use_result(), mysqli_num_rows($res), $res->fetch_assoc(), mysqli_num_rows($res), $res->fetch_assoc(), mysqli_num_rows($res));' Expected result: ---------------- Warning: mysqli_num_rows(): Function cannot be used with MYSQL_USE_RESULT in Command line code on line 1 Warning: mysqli_num_rows(): Function cannot be used with MYSQL_USE_RESULT in Command line code on line 1 object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(1) ["lengths"]=> array(1) { [0]=> int(1) } ["num_rows"]=> int(1) ["type"]=> int(0) } int(0) array(1) { [1]=> string(1) "1" } int(0) NULL int(1) ----- here is the difference Actual result: -------------- Warning: mysqli_num_rows(): Function cannot be used with MYSQL_USE_RESULT in Command line code on line 1 Warning: mysqli_num_rows(): Function cannot be used with MYSQL_USE_RESULT in Command line code on line 1 object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(1) ["lengths"]=> array(1) { [0]=> int(1) } ["num_rows"]=> int(1) ["type"]=> int(0) } int(0) array(1) { [1]=> string(1) "1" } int(0) NULL int(0) --- should have been 1 -- Edit bug report at https://bugs.php.net/bug.php?id=55582&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=55582&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=55582&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=55582&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=55582&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=55582&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=55582&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=55582&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=55582&r=needscript Try newer version: https://bugs.php.net/fix.php?id=55582&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=55582&r=support Expected behavior: https://bugs.php.net/fix.php?id=55582&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=55582&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=55582&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=55582&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=55582&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=55582&r=dst IIS Stability: https://bugs.php.net/fix.php?id=55582&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=55582&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=55582&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=55582&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=55582&r=mysqlcfg