0

已创建查询。

用这个查询更新表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();并且没有错误

4

0 回答 0