php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55582 mysqli_num_rows() returns always 0 for unbuffered, when mysqlnd is used
Submitted: 2011-09-05 09:49 UTC Modified: 2011-09-05 15:35 UTC
From: andrey@php.net Assigned: andrey (profile)
Status: Closed Package: MySQLi related
PHP Version: 5.4SVN-2011-09-05 (SVN) OS: all
Private report: No CVE-ID: None
 [2011-09-05 09:49 UTC] andrey@php.net
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-09-05 15:29 UTC] andrey@php.net
Automatic comment from SVN on behalf of andrey
Revision: http://svn.php.net/viewvc/?view=revision&revision=316188
Log: Fix for Bug #55582 mysqli_num_rows() returns always 0 for unbuffered, when mysqlnd is used
 [2011-09-05 15:35 UTC] andrey@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: andrey
 [2011-09-05 15:35 UTC] andrey@php.net
-Status: Assigned +Status: Closed
 [2011-09-05 15:35 UTC] andrey@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

Fixed in SVN, to appear in 5.3.9
 [2011-09-05 15:37 UTC] andrey@php.net
Automatic comment from SVN on behalf of andrey
Revision: http://svn.php.net/viewvc/?view=revision&revision=316189
Log: missing from previous commit for #55582
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 07:01:29 2024 UTC