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.