MySQL Unbuffered Query Behavior Change
| From: | Nicholas Williams | Date: | Mon, 14 Mar 2011 17:32:33 +0000 |
| Subject: | MySQL Unbuffered Query Behavior Change | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-47722@lists.php.net to get a copy of this message | ||
I was previously on PHP 5.1.6 and was using the following code:
$dbr = mysql_unbuffered_query($query, $this->con);
while($row = mysql_fetch_array($dbr, $assoc ? MYSQL_ASSOC : MYSQL_NUM))
$this->result[] = $row;
$this->rows = mysql_num_rows($dbr);
It worked properly. The documentation at
http://www.php.net/manual/en/function.mysql-num-rows.php
indicates that
mysql_num_rows won't return the correct result on unbuffered queries until
all of the rows had been fetched, but since I was looping through and
fetching all rows with mysql_fetch_array, it worked properly and wasn't a
problem.
I've upgraded to PHP 5.3.5 and now mysql_num_rows always returns 0. I am
fetching all rows before calling mysql_num_rows, just like the documentation
says to do, so mysql_num_rows should return the correct result. Why is it
not? Is the documentation wrong now (should it have been updated to say that
mysql_num_rows now NEVER works with unbuffered queries instead of saying you
have to fetch all rows first)? Is there a bug in PHP? Or am I doing
something wrong and it just coincidentally worked before?
Thanks,
Nick