I have a stored procedure with the following structure:
CREATE PROCEDURE MyStoredProcedure(IN code INTEGER) BEGIN
DECLARE EXIT handler FOR SQLEXCEPTION
BEGIN
ROLLBACK;
SET autocommit = 1;
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
END;
SET autocommit = 0;
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
-- code here
COMMIT;
SET autocommit = 1;
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
END;
And I’m calling it via PDO using:
$dbh->prepare("CALL MyStoredProcedure(?);");
It works fine, but I need a way to dected from PHP if the stored procedure has raised an exception and it got “rollbacked” or it went through without errors. Can this be done?
Add an out param to the procedure and in case of error put there 0, or 1 on success