0

I wrote a utility for updating the DB from a list of numbered .sql update files. The utility stores inside the DB the index of the lastAppliedUpdate. When run, it reads lastAppliedUpdate and applies to the db, by order, all the updates folowing lastAppliedUpdate, and then updates the value of lastAppliedUpdate in the db. Basically simple.

The issue: the utility successfully applies the needed updates, but then when trying to store the value of lastAppliedUpdate, an error is encountered:

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.

Any ideas, what does it mean, and how can be resolved?

Below is the essence of the code. It's a php code within the Yii framework.

foreach ($numericlyIndexedUpdateFiles as $index => $filename)
{
    $command = new CDbCommand (Yii::app()->db, file_get_contents ($filename));
    $command->execute();
}
$metaData = MDbMetaData::model()->find();
$metaData->lastAppliedUpdate = $index;
if (!$metaData->save()) throw new CException ("Failed to save metadata lastAppliedUpdate."); 
// on this line, instead of throwing the exception that my code throws, if any,
// I receive the described above error

mysql version is: 5.1.50, php version is: 5.3

edit: the above code is done inside a transaction, and I want it to.

shealtiel
  • 8,020
  • 18
  • 50
  • 82

2 Answers2

1

Check it out

PDO Unbuffered queries

You can also look at the to set PDO:MYSQL_ATTR_USE_BUFFERED_QUERY

http://php.net/manual/en/ref.pdo-mysql.php

Community
  • 1
  • 1
Shakti Singh
  • 84,385
  • 21
  • 134
  • 153
0

The general answer is that you have to retrieve all the results of the previous query before you run another, or find out how to turn off buffered queries in your database abstraction layer.

Since I don't know the syntax to give you with these mysterious classes you're using (not a Yii person), the easy fix solution is to close the connection and reopen it between those two actions.

Dan Grossman
  • 51,866
  • 10
  • 112
  • 101
  • Thanks, I do it inside a transaction, and want it to be done this way. Does your answer change taking this into account? – shealtiel Jan 23 '11 at 13:12