From: memoimyself at yahoo dot com dot br Operating system: Linux PHP version: 5.1.2 PHP Bug Type: PDO related Bug description: Variable holding query results has to be unset
Description: ------------ When running more than one query in a row with PDO, if the result set is assigned to a variable with the same name (e.g. $result) each time, only the first assignment works properly: from the second time on, the variable will contain an empty result set. I have tested my code in two different setups: Linux (A2 Web Hosting server running PHP 5.1.2) and Windows XP (my test server, also running PHP 5.1.2). This problem ONLY occurs in the first setup (Linux). It does not matter which "fetch style" is used. I have worked around this problem by unsetting the result variable each time as soon as all data has been fetched from it. Reproduce code: --------------- $dbh = new PDO(BD_DSN, BD_USERNAME, BD_PWD); if ($result = $dbh->query('SELECT * FROM table_1')) { $all_rows_1 = $result->fetchAll(PDO::FETCH_OBJ); } if ($result = $dbh->query('SELECT * FROM table_2')) { $all_rows_2 = $result->fetchAll(PDO::FETCH_OBJ); } Expected result: ---------------- If both tables actually contain data, $all_rows_1 and $all_rows_2 should both contain all the data from each table. Actual result: -------------- When code similar to the example is run on my Windows XP test server, everything works as expected. When, however, the same code is run on the Linux production server, $all_rows_2 will contain an empty array rather than an array with objects representing each row from the table. If I add unset($result) after each $result->fetchAll(PDO::FETCH_OBJ), then everything works well on the Linux server as well. Curiously, I have had no problems assigning other types of object the variables with the same name in a sequence or loop (e.g. when creating XML elements in a loop and assigning them to a variable with the same name each time). -- Edit bug report at http://bugs.php.net/?id=36286&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=36286&r=trysnapshot44 Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=36286&r=trysnapshot51 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=36286&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=36286&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=36286&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=36286&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=36286&r=needscript Try newer version: http://bugs.php.net/fix.php?id=36286&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=36286&r=support Expected behavior: http://bugs.php.net/fix.php?id=36286&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=36286&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=36286&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=36286&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36286&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=36286&r=dst IIS Stability: http://bugs.php.net/fix.php?id=36286&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=36286&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=36286&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=36286&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=36286&r=mysqlcfg