Mysql更新了两个表。获取错误:在其他未缓冲的查询处于活动状态时无法执行查询

时间:2013-10-10 19:23:21

标签: mysql

创建查询。

使用此查询更新表2_1_transactionpartners

然后,另一个表(2_1_journal)中的值与表2_1_transactionpartners中的值相同,请更新另一个表。

BEGIN; 
UPDATE 2_1_transactionpartners SET 
PreviousCompanyName = CASE NumberRenamed WHEN ? THEN CompanyName END,
CompanyName = CASE NumberRenamed WHEN ? THEN ? END,
/* others WHEN ? THEN ? END */
BankAccountNumber = CASE NumberRenamed WHEN ? THEN ? END 
WHERE NumberRenamed IN (?); 

/* here starts problem */
UPDATE 2_1_journal 
INNER JOIN 2_1_transactionpartners ON 
(2_1_journal.TransactionPartnerName = 2_1_transactionpartners.PreviousCompanyName) 
SET 2_1_journal.TransactionPartnerName = 2_1_transactionpartners.CompanyName; 

COMMIT;

经过测试,看到所有更新。但得到这样的错误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.

如果将查询分成两个查询。第二个查询,如

UPDATE 2_1_journal 
INNER JOIN 2_1_transactionpartners ON (2_1_journal.TransactionPartnerName = 2_1_transactionpartners.PreviousCompanyName) 
SET 2_1_journal.TransactionPartnerName = 2_1_transactionpartners.CompanyName;

然后所有工作都没有错误。我可以将这两个更新用于一个查询而不会出错吗?

更新

执行语句(带有2个查询)后放置$stmt->closeCursor();并且没有错误

0 个答案:

没有答案