0

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.

IMSoP
  • 89,526
  • 13
  • 117
  • 169
saionachi
  • 397
  • 1
  • 5
  • 21
  • Does this answer your question? [Laravel: Using try...catch with DB::transaction()](https://stackoverflow.com/questions/22906844/laravel-using-try-catch-with-dbtransaction) – N69S May 10 '22 at 09:51
  • @N69S Tried that, yeah. Unfortunately, when adding the `DB::commit()` it returns the same "There is no active transaction" as each stored procedures commits the changes already. – saionachi May 10 '22 at 10:08
  • The your stored procedure has a transaction defined in it that is conflicting. look for `BEGIN TRAN` in your procedure definition – N69S May 10 '22 at 13:09

0 Answers0