ZF-5576: Can't execute subsequent query after multiple queries from same Pdo_Mysql->exec() call

Issue Type: Bug Created: 2009-01-18T05:12:29.000+0000 Last Updated: 2012-11-20T20:53:25.000+0000 Status: Closed Fix version(s): Reporter: Mark (lightflowmark) Assignee: None Tags: - Zend_Db

Related issues: - ZF-2101



<pre class="highlight">
        include 'Zend/Loader.php';

  $pdoParams = array(

$params = array(
    'host'           => 'localhost',
    'username'       => 'test',
    'password'       => 'xxxxxx',
    'dbname'         => 'test_db',
    'driver_options' => $pdoParams

$db = Zend_Db::factory('Pdo_Mysql', $params);

        $sql0="DROP TABLE IF EXISTS someTable";
        $sql1="CREATE TABLE someTable (id INT);";
        $sql2="INSERT INTO someTable (id) VALUES (1)";

The above code works fine. However, attempting to execute more than one query in each exec() call does not:

<pre class="highlight">
        $sql1="DROP TABLE IF EXISTS someTable; CREATE TABLE someTable (id INT);";
        $sql2="INSERT INTO someTable (id) VALUES (1)";

Execution of $sql2 fails with 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.

Note that

<pre class="highlight">
        $sql1="DROP TABLE IF EXISTS someTable; CREATE TABLE someTable (id INT);";

works fine on it's own - it's the subsequent call that fails.

This is more irritating than it appears, as it makes loading query data from files more fiddly - for instance in my unit test setUp() I have something like

<pre class="highlight">
      $sql = file_get_contents('createTestSchema.sql');

where createTestSchema.sql consists of a number of CREATE TABLE & INSERT statements. This then basically kills the $db object - it can't be used for any other queries without giving this error.

Assuming it's linked to the similar stored procedure problem, there's some discussion here that it's specific to FreeBSD; I'm certainly running FreeBSD but haven't tested it elsewhere.


Posted by Alexander Steshenko (lcf) on 2009-02-19T07:43:31.000+0000

I've got absolutely the same bug on my home machine: Windows Vista HP, mysql 5.0.45, php 2.5.4 (and 2.5.5 in cgi mode fails too), so It's not because of FreeBSD. Must be something wrong with PDO, but i couldn't find an answer.

Posted by Rob Allen (rob) on 2012-11-20T20:53:25.000+0000

Bulk change of all issues last updated before 1st January 2010 as "Won't Fix".

Feel free to re-open and provide a patch if you want to fix this issue.

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.