/** * Closes transaction. * * @param string $doCommit True - do commit, rollback otherwise. Rollback is also always performed if a sql failed within this transaction. * * @return bool True - successful commit, False - otherwise */ function DBend($doCommit = true) { global $DB; $result = false; if (!isset($DB['DB']) || empty($DB['DB'])) { return $result; } if ($DB['TRANSACTIONS'] == 0) { info('POSSIBLE ERROR: Used incorrect logic in database processing, transaction not started!'); return $result; } $DBresult = $doCommit && $DB['TRANSACTION_NO_FAILED_SQLS']; if ($DBresult) { $DBresult = DBcommit(); } else { DBrollback(); } $DB['TRANSACTIONS'] = 0; return !is_null($doCommit) && $DBresult ? $doCommit : $DBresult; }
function DBend($result = null) { global $DB; //SDI('DBend(): '.$DB['TRANSACTIONS']); if ($DB['TRANSACTIONS'] != 1) { $DB['TRANSACTIONS']--; if ($DB['TRANSACTIONS'] < 1) { $DB['TRANSACTIONS'] = 0; $DB['TRANSACTION_STATE'] = false; info('POSSIBLE ERROR: Used incorect logic in database processing, transaction not started!'); } return $DB['TRANSACTION_STATE']; } $DB['TRANSACTIONS'] = 0; if (is_null($result)) { $DBresult = $DB['TRANSACTION_STATE']; } else { $DBresult = $result && $DB['TRANSACTION_STATE']; } //SDI('Result: '.$result); if ($DBresult) { // OK $DBresult = DBcommit(); } $msg = S_TRANSACTION . ': ' . S_COMMITED_BIG; if (!$DBresult) { // FAIL DBrollback(); $msg = S_TRANSACTION . ': ' . S_ROLLBACKED_BIG; } if ($DB['COMMENTS']) { info($msg); } $result = !is_null($result) && $DBresult ? $result : $DBresult; return $result; }
function DBend($result = true) { global $DB; //SDI('DBend(): '.$DB['TRANSACTIONS']); if ($DB['TRANSACTIONS'] != 1) { $DB['TRANSACTIONS']--; if ($DB['TRANSACTIONS'] < 1) { $DB['TRANSACTIONS'] = 0; $DB['TRANSACTION_STATE'] = false; info('POSSIBLE ERROR: Used incorrect logic in database processing, transaction not started!'); } $DB['TRANSACTION_STATE'] = $result && $DB['TRANSACTION_STATE']; return $DB['TRANSACTION_STATE']; } $DB['TRANSACTIONS'] = 0; $DBresult = $result && $DB['TRANSACTION_STATE']; //SDI('Result: '.$result); if ($DBresult) { // OK $DBresult = DBcommit(); } if (!$DBresult) { // FAIL DBrollback(); } $result = !is_null($result) && $DBresult ? $result : $DBresult; return $result; }