ID: 35793 Comment by: email at steffenweber dot net Reported By: deadman_great at mail dot ru Status: Feedback Bug Type: PDO related Operating System: RH Fedora Core 2 PHP Version: 5CVS-2005-12-25 (snap) Assigned To: Wez New Comment:
I´ve tried php5.1-200604091430.tar.bz2 and the error is still there. Previous Comments: ------------------------------------------------------------------------ [2006-04-09 07:39:25] [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 Try the next snapshot dated after this message. ------------------------------------------------------------------------ [2006-03-23 00:25:26] qlogix at gmail dot com I can confirm the statement on Centos 4.1, PHP 5.1.2, Mysql 4.1.16 "You cannot use the same variable for a PDOStatement object twice. As others have pointed out it works when you set this variable to null in between." <?php $db = new PDO(SQL_DSN,SQL_USER,SQL_PASSWORD); $db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); $result = $db->query('SELECT COUNT(*) FROM Locations'); echo $result."<br>"; $row = $result->fetchAll(PDO::FETCH_ASSOC); /* Comment the next line out and script returns an error */ //$result = null; $result = $db->query('SELECT COUNT(*) FROM Accounts'); echo $result."<br>"; $row = $result->fetch(PDO::FETCH_ASSOC); /* This line causes the error */ ?> With line "$result = null;" commented out: Object id #2 Object id #3 PDOException Object ( [message:protected] => SQLSTATE[HY000]: General error: 2050 With line "$result = null;" not commented out: Object id #2 Object id #2 No error message (script works) ------------------------------------------------------------------------ [2006-03-21 18:37:15] email at steffenweber dot net I can confirm that this error does not occur on Windows XP + PHP 5.1.2 + MySQL 5.0.18. It does happen for me on Gentoo Linux + PHP 5.1.2 + MySQL 4.1.16. You cannot use the same variable for a PDOStatement object twice. As others have pointed out it works when you set this variable to null in between. ------------------------------------------------------------------------ [2006-03-18 22:09:27] gg15 at gmx dot net $result = $db->query('SELECT COUNT(*) FROM XYZ'); $row = $result->fetch(PDO::FETCH_ASSOC); $result->closeCursor(); $result = $db->query('SELECT * FROM XYZ'); $row = $result->fetch(PDO::FETCH_ASSOC); // this one throws the error an $result = null; between the statements fixes the issue, so I think this is a problem of php... ------------------------------------------------------------------------ [2006-03-11 10:42:51] peres dot yzqk8 at mailnull dot com I'd got same problem with this piece of code: $s = $db->query("SELECT * FROM test ORDER BY poledrugie;"); var_dump($s->fetchAll()); $s = $db->query("SELECT * FROM test ORDER BY poletrzecie;"); var_dump($s->fetchAll()); Changed it to: $s = $db->query("SELECT * FROM test ORDER BY poledrugie;"); var_dump($s->fetchAll()); $st = $db->query("SELECT * FROM test ORDER BY poletrzecie;"); var_dump($st->fetchAll()); So I think it's wrong use of PHP objects... ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/35793 -- Edit this bug report at http://bugs.php.net/?id=35793&edit=1