|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-02-09 11:46 UTC] abouzekry at gmail dot com
Description:
------------
the same code runs on php5.2.0 without any problems, while it's problematic with php5.2.5 i don't know why!, it insists on giving
me the following message...
Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute
however i closed the cursor after each result fetch!!!!
Reproduce code:
---------------
if(isset($_POST['user_name'], $_POST['pass']))
{
/* check wether the user exists or not */
$result = $db->query("CALL proc_check_user('{$_POST['user_name']}', '{$_POST['pass']}')")
or die('0-1-Database-Query-Error-login.php:'.print_r($db->errorInfo()));
$row = $result->fetchAll(PDO::FETCH_ASSOC)
or die('0-2-Database-Fetch-Error-login.php:'.print_r($db->errorInfo()));
/* close the DB cursor to be able to perform the other querie(s)*/
$result->closeCursor();
/* if the user doesn't exist exit prematurely! */
if($row['userExists'] == 0)
{
exit('0-2-Authentication-Error-login.php: User Doesnt Exist!');
}
/* get the user_id and full_name */
$result = $db->query("CALL proc_get_user_data('{$_POST['user_name']}', '{$_POST['pass']}')")
or die('0-3-Database-Query-Error-login.php:'.print_r($db->errorInfo()));
$row = $result->fetch(PDO::FETCH_ASSOC);
}
Expected result:
----------------
the machine with php5.2.0 installed when running the same code produces
a correct authentication for valid users (POSTed) and error for invalid users.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 21:00:02 2025 UTC |
Same issue with PHP 5.2.10 (Linux/Mac/Windows) with a similar code: $this->dbh = new PDO($this->options['dsn'], $this->options['username'], $this->options['password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES '.$this->options['charset'])); $this->dbh->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); $this->dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $sth = $this->dbh->prepare($_stored_proc_1); $sth->bindValue('I_bind', $value, PDO::PARAM_STR); $sth->execute(); $object = $sth->fetchAll(PDO::FETCH_ASSOC); $sth->closeCursor(); $sth = $this->dbh->prepare($_stored_proc_2); $sth->bindValue('I_bind', $value, PDO::PARAM_STR); $sth->execute(); $object = $sth->fetchAll(PDO::FETCH_ASSOC); $sth->closeCursor(); However no problem at all if I install php 5.2.10 Zend Community Edition ... :-)I am using XAMPP (PHP 5.3.0 on Windows XP) and I am able to execute succeeding prepared statements with no problem as long as I call $PDOStatement->closeCursor() after I'm done with the previous one. The problem arises with MySQL stored procedures. PDO will execute and successfully retrieve records from the first stored procedure but all other statements afterwards WILL NOT EXECUTE, and I too get the error below: "Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute." I tried adding in the aforemention attribute to no avail. Here is a snippet from a script I used to test this: $PDOStatement = $PDO->prepare('SELECT * FROM MagicCards WHERE cardID = ?'); $PDOStatement->bindValue(1, 1600); $PDOStatement->execute(); $PDOStatement->setFetchMode(\PDO::FETCH_ASSOC); $rows = $PDOStatement->fetchAll(); $PDOStatement->closeCursor(); $PDOStatement = NULL; print_r($rows); // works as expected $PDOStatement = $PDO->prepare('CALL uspGetMagicCardByKey(?)'); $PDOStatement->bindValue(1, 10); $PDOStatement->execute(); $PDOStatement->setFetchMode(\PDO::FETCH_ASSOC); $rows = $PDOStatement->fetchAll(); $PDOStatement->closeCursor(); $PDOStatement = NULL; print_r($rows); //works as expected $PDOStatement = $PDO->prepare('SELECT * FROM MagicCards WHERE cardID = ?'); $PDOStatement->bindValue(1, 1600); $PDOStatement->execute(); //errors out right here with the HY000 error $PDOStatement->setFetchMode(\PDO::FETCH_ASSOC); $rows = $PDOStatement->fetchAll(); $PDOStatement->closeCursor(); $PDOStatement = NULL; print_r($rows); //doesn't get this far The workaround would be to drop in your SQL from your stored procedure directly as an argument to $PDO->prepare(). But if you are doing any other modifications before or after that main SELECT statement, this is not a feasible solution. This is a critical bug that needs to be fixed ASAP.