I'm using phpBB and this code is not working as expected. It's simply using the phpBB sql_transaction
function to start an sql transaction, then commit it. But the exception should be thrown half way through and issue a rollback using the same function.
However, the rollback never happens. Queries 1 and 2 take effect, and I can't get them to rollback.
The documentation states that if there is an sql error, it will automatically issue a rollback, but I'm trying to roll it back if there is a php error, such as a timeout or something.
I'm using MySQL 5.7, phpBB 3.0.11, and php 5.6.
Can someone point out the issue?
$db->sql_transaction('begin');
try {
$sql = 'UPDATE aaa_temp SET method = "a" WHERE id = 1';
$db->sql_query($sql);
$sql = 'UPDATE aaa_temp SET method = "b" WHERE id = 2';
$db->sql_query($sql);
throw new Exception('OMG TOTAL ERROR');
$sql = 'UPDATE aaa_temp SET method = "c" WHERE id = 3';
$db->sql_query($sql);
} catch (Exception $ex) {
$db->sql_transaction('rollback');
trigger_error($ex->getMessage(), E_USER_ERROR);
}
$db->sql_transaction('commit');
Thanks in advance! I know it's got to be something really simple and stupid, but let me know if more detail is needed.
EDIT: Just so it's clear, I'm talking about SQL transactions in MySQL.