ID:               36144
 User updated by:  php at kanariepiet dot com
 Reported By:      php at kanariepiet dot com
-Status:           Bogus
+Status:           Open
 Bug Type:         MySQL related
 Operating System: Linux
 PHP Version:      5.1.2
 New Comment:

This certainly is a bug. There's nothing wrong with script1, 
there's also nothing wrong with script2.
If you put script2 and script1 together in one script, the 
problem does not occur, so one of the key factors is the 
persistent connections we're using. I don't believe the 
persistent connections are handled by the MySQL library.
Somehow PHP doesn't clean up nicely after script2 
(mysql_free_result has no effect), leaving the MySQL 
connection in the pool tainted.

Futhermore, if you do a var_dump($res) after each 
mysql_fetch_assoc($res) in script1, you'll see that the 
first time it'll show $res is a 'mysql result' type, but the 
second time $res is 'Unknown' (which is not the case if the 
script did perform like it should). Somehow $res gets 
altered in the while() loop.


Previous Comments:
------------------------------------------------------------------------

[2006-01-24 15:54:37] [EMAIL PROTECTED]

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

RTFM.

------------------------------------------------------------------------

[2006-01-24 15:30:13] php at kanariepiet dot com

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 this bug report at http://bugs.php.net/?id=36144&edit=1

Reply via email to