开发者

PDO connector unable to be used on page with multiple instances

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


Apparently that is caused by a bug in PHP and lack of support for stored procedures on Windows machines.

Please try the following: http://bugs.php.net/bug.php?id=39858

Looking at the very last comment: 1221253320 it seems to have been fixed, you can try update your PHP To the latest version. 5.3

my advice: If your using a pre packaged "server" kit such as xampp then you should scrap that all together, partition 2GB of your hard drive using the Storage Extender in Storage Management, Install MySql,PHP,Apache seperatly and then configure them.

use that latest snapshot of PHP and the latest MySql Distro, Migrate your application and database to the new install, kick your computer and it should run fine.

I would bet that it could be down to the MySql Client Libs as well, Upgrade them

Some related links im coming across:

  • I get 2014 Cannot execute queries while other unbuffered queries are active when doing exec with PDO
  • http://www.php.net/manual/en/ref.pdo-mysql.php#84688


PDO Unbuffered queries & Stored Proc.

PDO Unbuffered queries

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜