在Laravel/MySQL中的交易中调用存储程序
在我的应用程序中,我有一个调用多个存储过程的函数,并在数据库上执行多个插入,并且将其包装在db :: Trassaction()
中回头。
public function myFunction() {
DB::transaction(function () {
DB::statement("CALL StoredProcedure()");
DB::statement("CALL StoredProcedure2()");
});
}
当我使用php 7.4时,这正常工作,但是现在我正在升级到PHP 8.0,它将引发pdoexception:没有活动的事务
。搜索后,似乎已经提出了第一个存储过程,因此结束了交易。我的目标是如果第二个失败,则在第一个存储过程中回滚。关于如何解决这个问题的任何建议?
我目前正在使用PHP 8.0中的Laravel 9,并计划将其升级到PHP 8.1。
In my application, I have a function that calls multiple stored procedure and do multiple inserts on the database and I'm wrapping it in a DB::transaction()
so if any of the insert queries fail it rolls back.
public function myFunction() {
DB::transaction(function () {
DB::statement("CALL StoredProcedure()");
DB::statement("CALL StoredProcedure2()");
});
}
This works fine when I'm using PHP 7.4 but now that I'm upgrading to PHP 8.0 it throws a PDOException: There is no active transaction
. Upon searching, it seems like the first stored procedure is being committed already and therefore ending the transaction. My goal is to rollback changes in first stored procedure if the second one fails. Any suggestion on how to do workaround for this issue?
I'm currently using Laravel 9 in PHP 8.0 and planning on upgrading it to PHP 8.1 as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论