diff options
author | Kevin Chabowski <kevin@kch42.de> | 2013-10-04 00:10:44 +0200 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2013-10-04 00:10:44 +0200 |
commit | 31fa704ef9e1aa03cda080c757d7e0011663b99d (patch) | |
tree | ad0dd14256b92775da2cc48079ed98fcb4696c52 /ratatoeskr/sys/db.php | |
parent | a2e489ace560bc104ea8f85cc9a09b685d1955be (diff) | |
parent | cb2fad2b1c6a173e6f20ef48a29b3bbe491d6f5e (diff) | |
download | ratatoeskr-cms-31fa704ef9e1aa03cda080c757d7e0011663b99d.tar.gz ratatoeskr-cms-31fa704ef9e1aa03cda080c757d7e0011663b99d.tar.bz2 ratatoeskr-cms-31fa704ef9e1aa03cda080c757d7e0011663b99d.zip |
Merge branch 'develop'
Diffstat (limited to 'ratatoeskr/sys/db.php')
-rw-r--r-- | ratatoeskr/sys/db.php | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/ratatoeskr/sys/db.php b/ratatoeskr/sys/db.php index 0b4bb4a..36d5348 100644 --- a/ratatoeskr/sys/db.php +++ b/ratatoeskr/sys/db.php @@ -87,34 +87,51 @@ function qdb() } /* - * Function: transaction + * Class: Transaction * - * Executes function $f and wraps it in a transaction. - * If $f has thrown an exception, the transactrion will be rolled back and the excetion will be re-thrown. - * Otherwise the transaction will be committed. - * - * Parameters: - * $f - A function / callback. + * Makes using transactions easier. */ -function transaction($f) +class Transaction { - global $db_con; + public $startedhere; - if($db_con->inTransaction()) - call_user_func($f); - else + /* + * Constructor: __construct + * + * Start a new transaction. + */ + public function __construct() { - try - { + global $db_con; + $this->startedhere = !($db_con->inTransaction()); + if($this->startedhere) $db_con->beginTransaction(); - call_user_func($f); + } + + /* + * Function: commit + * + * Commit the transaction. + */ + public function commit() + { + global $db_con; + + if($this->startedhere) $db_con->commit(); - } - catch(Exception $e) - { + } + + /* + * Function: rollback + * + * Toll the transaction back. + */ + public function rollback() + { + global $db_con; + + if($this->startedhere) $db_con->rollBack(); - throw $e; - } } } |