[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-db
Subject:    [PHP-DB] MySQL Unbuffered Query Behavior Change
From:       Nicholas Williams <nicholas () dnscrawler ! com>
Date:       2011-03-14 17:32:33
Message-ID: AANLkTinSfaB249wUGg-Y+fTz0W4oQEqCVDd3jvh_JauN () mail ! gmail ! com
[Download RAW message or body]


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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic