php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35529 pdo_mysql->rowCount does not work with Select
Submitted: 2005-12-03 08:29 UTC Modified: 2005-12-04 01:13 UTC
From: nitinvaishnav at gmail dot com Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5.1.1 OS: windows 2000
Private report: No CVE-ID: None
 [2005-12-03 08:29 UTC] nitinvaishnav at gmail dot com
Description:
------------
I using php 5.1.1 on IIS with 4.1.10a. The test database have 3 rows, the rowCount function returns 0, but foreach dumps 3 records of the table. But the rowCount returns correct result with INSERT, UPDATE and DELETE.

Reproduce code:
---------------
$Con = new PDO('mysql:host=localhost;dbname=nitin', 'root', '');
$Res = $Con->query('select * from test');
echo('rowCount: ' . $Res->rowCount() . "\n\n");

foreach ($Res as $Record) {
	var_dump($Record);
}


Expected result:
----------------
rowCount: 3

array(2) {
  ["test_int1"]=>
  string(1) "1"
  [0]=>
  string(1) "1"
}
array(2) {
  ["test_int1"]=>
  string(1) "1"
  [0]=>
  string(1) "1"
}
array(2) {
  ["test_int1"]=>
  string(1) "1"
  [0]=>
  string(1) "1"
}


Actual result:
--------------
rowCount: 0

array(2) {
  ["test_int1"]=>
  string(1) "1"
  [0]=>
  string(1) "1"
}
array(2) {
  ["test_int1"]=>
  string(1) "1"
  [0]=>
  string(1) "1"
}
array(2) {
  ["test_int1"]=>
  string(1) "1"
  [0]=>
  string(1) "1"
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-03 08:30 UTC] nitinvaishnav at gmail dot com
I using php 5.1.1 on IIS with mysql 4.1.10a. The test database have 3 rows, the rowCount function returns 0, but foreach dumps 3 records of the table. But the rowCount returns correct result with INSERT, UPDATE and DELETE.
 [2005-12-03 13:07 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.1-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.1-win32-latest.zip


 [2005-12-03 17:24 UTC] wez@php.net
PDO uses forward-only unbuffered cursors.
The row count is not know until all the rows have been retrieved.

See http://netevil.org/node.php?nid=703&SC=1#comments
for more information.
 [2005-12-03 19:29 UTC] nitinvaishnav at gmail dot com
thanks for information.
but following code also not work properly, the second rowCount also returns 0.

$Con = new PDO('mysql:host=localhost;dbname=nitin', 'root', '');
$Res = $Con->query('select * from test', array(PDO_MYSQL_ATTR_USE_UNBUFFERED_QUERY => true));
echo('1. rowCount: ' . $Res->rowCount() . "\n\n");

$Result = $Res->fetchAll();
var_dump($Result);


echo('2. rowCount: ' . $Res->rowCount() . "\n\n");
 [2005-12-04 01:13 UTC] wez@php.net
count($Result) will give you the answer you're looking for.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 10 18:01:28 2024 UTC