gpt4 book ai didi

php - 一个接一个地执行多个数据库更新(一般错误 2014 )

转载 作者:行者123 更新时间:2023-11-29 14:55:16 27 4
gpt4 key购买 nike

我编写了一个实用程序,用于从编号的 .sql 更新文件列表中更新数据库。该实用程序将最后一次应用更新的索引存储在数据库内。运行时,它读取lastAppliedUpdate并按顺序将lastAppliedUpdate之后的所有更新应用于数据库,然后更新数据库中lastAppliedUpdate的值。基本上很简单。

问题:该实用程序成功应用了所需的更新,但在尝试存储 lastAppliedUpdate 的值时遇到错误:

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.

任何想法,这意味着什么,以及如何解决?

下面是代码的本质。这是 Yii 框架内的 php 代码。

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版本是:5.1.50,php版本是:5.3

编辑:上面的代码是在事务内完成的,我希望如此。

最佳答案

检查一下

PDO Unbuffered queries

您还可以查看设置 PDO:MYSQL_ATTR_USE_BUFFERED_QUERY

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

关于php - 一个接一个地执行多个数据库更新(一般错误 2014 ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4773935/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com