I know this has to be a simple fix and I partially understand why I am getting this error but don’t know how to fix it. I’ve looked over the docs but can’t find a solution other than using buffered queries option. I have tried that as well but it doesn’t work.
The error is: PDO Cannot execute queries while other unbuffered queries are active
The error is coming from the line where I am building the $result array.
foreach($phones as $phone)
{
$stmt = db::getInstance()->prepare("CALL phones(:phone)");
$stmt->bindParam(':phone', $phone, PDO::PARAM_INT, 10);
$stmt->execute();
$result[] = db::getInstance()->query("SELECT @phone;")->fetchAll(PDO::FETCH_ASSOC);
}
Let’s take an example table
an example procedure
and some sample data
Using PDOStatement it is possible to fetch the result set from the stored procedure.
prints
result set: 2 | 3 | 4 | 5 |(test environment: php 5.3.1/winxp, mysql 5.1.37)
The
do { } while($stmt->nextRowset());loop probably solves your “original” problem as well.