I have PHP code that execute a stored procedure 10 times. If one stored procedure call fails, it should continue on, and at the end commit the transaction.
It basically looks like this:
$connection = getConn();
foreach($row as $i=>$j) {
$SQL = "BEGIN MYPROC.EXECUTE(:VAL1, :VAL2); END;";
$statement = OCIParse($connection, $SQL);
oci_bind_by_name($statement, 'VAL1', $row[i]['FIRSTVAL']);
oci_bind_by_name($statement, 'VAL2', $row[i]['SECONDVAL']);
$success = @OCIExecute($statement, OCI_DEFAULT);
if(!$success) {
print 'Exception in stored proc call';
}
else {
print 'Success';
}
}
oci_commit($connection);
My question is, if there is an exception raised in, say, the 5th stored proc call, will that roll back all the stored proc calls up to that point?
As long as each procedure is executed in the same session, and none of them issue a commit, then the changes they make can be rolled back. You should open the connection outside the loop, then do all your work within that. As it stands now, you’re connecting each time through the loop, which is inefficient and won’t allow what you want to do. You should also take the commit statement outside the loop.
Something like this, perhaps: