ID:               36286
 Updated by:       [EMAIL PROTECTED]
 Reported By:      memoimyself at yahoo dot com dot br
-Status:           Open
+Status:           Feedback
 Bug Type:         PDO related
 Operating System: Linux
 PHP Version:      5.1.2
 New Comment:

Please try using this CVS snapshot:

  http://snaps.php.net/php5.1-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.1-win32-latest.zip




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

[2006-02-04 14:39:58] memoimyself at yahoo dot com dot br

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

Reply via email to