我的代码如下。
1) PHP代码
\DB::transaction(function () use ($id, $member_id) {
\DB::select(\DB::raw('call doJob(?,?,@pJobLogId)'), [$id, $member_id]);
});
2)存储过程,上面的doJob..
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
RESIGNAL;
END;
START TRANSACTION;
// codes(logic)...
COMMIT;
END
以上有问题吗?如果我应该放弃一笔交易,我应该放弃哪一笔交易?
另外我不知道双重事务是否会导致此类错误。 我看到了如下的错误日志,但这几乎不会发生。
SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction
最佳答案
根据MySql官方文档:
Section 13.3.3 Statements That Cause an Implicit Commit
Transactions cannot be nested. This is a consequence of the implicit commit performed for any current transaction when you issue a START TRANSACTION statement or one of its synonyms. https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html
关于php - 存储过程和包装它的 php 代码上的双重事务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55724107/