ID:               36286
 Comment by:       barry dot verdon at complinet dot com
 Reported By:      memoimyself at yahoo dot com dot br
 Status:           No Feedback
 Bug Type:         PDO related
 Operating System: Linux
 PHP Version:      5.1.2
 New Comment:

I have experienced the same thing on 5.1.3 on Debian. Here is the test
case I used

$db = new PDO(DSN, USERNAME, PASSWORD);

$stmt = $db->query('SELECT 1+1 AS answer');
$answer = $stmt->fetch(PDO::FETCH_ASSOC); // All fine here

$stmt = $db->query('SELECT 1+2 AS result');
$result = $stmt->fetch(PDO::FETCH_ASSOC); // Result is false


It does the same thing with a foreach loop. But if you named the
variables $stmt1 and $stmt2 is would work fine. It even caused a
problem when I had a class wrapping, not extending, PDOStatement,
slightly different error, on the __call magic method instead, but with
different variable names all worked fine.


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

[2006-02-12 01:00:03] php-bugs at lists dot php dot net

No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".

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

[2006-02-04 18:47:21] [EMAIL PROTECTED]

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



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

[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