Cannot execute queries while other unbuffered queries are active
Can’t execute subsequent query after multiple queries from same Pdo_Mysql->exec() call
Can’t execute multiple stored procedures with Pdo_Mysql
Using the following code found in the Zend Framework Quickstart: Create a Model and Database Table
try {
$schemaSql = file_get_contents('./schema.sqlite.sql');
$dbAdapter->getConnection()->exec($schemaSql);
echo PHP_EOL;
echo 'Database Created';
echo PHP_EOL;
if ($withData) {
$dataSql = file_get_contents('./data.sqlite.sql');
$dbAdapter->getConnection()->exec($dataSql);
echo 'Data Loaded.';
echo PHP_EOL;
}
} catch (Exception $e) {
echo 'AN ERROR HAS OCCURED:' . PHP_EOL;
echo $e->getMessage() . PHP_EOL;
return false;
}
Note that $dbAdapter->getConnection()->exec() gets called twice.
I encountered this issue when calling Pdo_Mysql->exec() or in the Zend Framework calling $dbAdapter->getConnection()->exec($schemaSql) one after the other.
One way to prevent the error was to call $dbAdapter->closeConnection() after each exec call. Another way I worked around this problem was to just execute the $schemaSql and the $dataSql in one exec call like below;
$schemaSql = file_get_contents('schema.sql', 1);
$dataSql = file_get_contents('data.sql', 1);
// use the connection directly to load sql in batches
$dbAdapter->getConnection()->exec($schemaSql . $dataSql);