From:             php at kanariepiet dot com
Operating system: Linux
PHP version:      5.1.2
PHP Bug Type:     *Database Functions
Bug description:  only one row when using persistent connections and unbuffered 
queries

Description:
------------
Assume you have a webserver serving two PHP scripts. Both PHP 
scripts use persistent MySQL database connections. Script one 
uses normal mysql_query calls, script two uses 
mysql_unbuffered_query calls.
Also, script one is doing additional mysql_query calls while 
retrieving the records of the first mysql_query (yes, an sql 
join would be better).

When script two (the one with mysql_unbuffered_query) 
finishes, and script one reuses the persistent database 
connection of script two, the resource identifier in script 
one gets lost after the first loop, resulting in only one 
returned row.
get_resource_type($res) should return 'mysql result', but will 
return 'Unknown'


Reproduce code:
---------------
Script1.html:
$db = mysql_pconnect ('host', 'user', 'pass');
print ('We are using MySQL thread: '. mysql_thread_id() .'<br />');

$res = mysql_query ("SELECT * FROM temp.documents");  // table with 1200
records

print ('mysql_num_rows() returned '. mysql_num_rows($res) .'<br />');

while ($row = mysql_fetch_assoc ($res)) {
  $res2 = mysql_query ("SELECT * FROM temp.attachments WHERE document = ".
$row['id']);
  while ($row2 = mysql_fetch_assoc ($res2))
    $row['attachments'][] = $row2;

  $documents[] = $row;
}

print ('number of documents: '. count ($documents));


Script2.html:
$db = mysql_pconnect ('host', 'user', 'pass');
print ('We are using MySQL thread: '. mysql_thread_id() .'<br />');
$res = mysql_unbuffered_query ("SELECT * FROM temp.documents");
while ($row = mysql_fetch_assoc ($res)) {
}

Expected result:
----------------
Open script2.html and note the thread id.
Keep opening script1.html until the thread id is the same as 
the one script2 used.
You should see this:
(script2.html)
We are using MySQL thread: 1439

(script1.html)
We are using MySQL thread: 1439
mysql_num_rows() returned 1200
number of documents: 1200

Actual result:
--------------
However, the output will be:
(script2.html)
We are using MySQL thread: 1439

(script1.html)
We are using MySQL thread: 1439
mysql_num_rows() returned 1200
number of documents: 1

-- 
Edit bug report at http://bugs.php.net/?id=36144&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=36144&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): 
http://bugs.php.net/fix.php?id=36144&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=36144&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=36144&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=36144&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=36144&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=36144&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=36144&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=36144&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=36144&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=36144&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=36144&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=36144&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=36144&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=36144&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=36144&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=36144&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=36144&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=36144&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=36144&r=mysqlcfg

Reply via email to