At the top of my php page, I include a connection script called by:
include("connector.php")
Connector.php
<?php
try
{
$db = new PDO('mysql:host=localhost;dbname=DB', 'USER', 'PW');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e)
{
echo $e->getMessage();
}
?>
I then make all subsequent calls on my pages as necessary. On one page in particular however, I initially make a call into a MySQL stored procedure:
$stmt = $db->prepare("CALL Procedure(:id)");
$stmt->bindParam(':id', $id);
$stmt->execute();
while($row=$stmt->fetch()) {
echo "<tr>
<td>".$row['ID']."</td>
<td>".$row['NAME']."</td>
</tr>";
}
There is no issue with my stored procedure but down the page when I try and make any subsequent calls, I get the usual PDO Mysql unbuffered queries error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2014 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.' in C:\page.php:261 Stack trace: #0 C:\page.php(261): PDOStatement->execute(Array) #1 {main} thrown in C:\page.php on line 261
Yes, I have tried using FetchAll, and NO I do not want to use the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute as we may switch off MySQL at a later point in time and I do not wish to rebuild based on every DB (not to mention even when I did include it did not work).
Any ideas why this might be happening? I could 'include' the connector.php file before every DB call but that seems repetitive and I'd have to $db->NULL every statement.
Note: this seems to only affect pages with calls into stored procedures. Any ideas?
Note: This is being run on a Windows machine with XAMPP 1.7.3 running Apache 2.2.14, PHP 5.3.1