创建查询。
使用此查询更新表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();
并且没有错误