Skip to content

Commit

Permalink
Merge pull request #22 from adrianhardy/master
Browse files Browse the repository at this point in the history
Support transactions in PHP 5.4
  • Loading branch information
Tom Walder committed Jul 30, 2014
2 parents ba4a3b1 + 8f05d91 commit 9730f54
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Docnet/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,26 @@ public function __construct($str_host, $str_user, $str_pass, $str_db = NULL, $in
*
* @returns \Docnet\Db
* @throws \Exception if mysqli::begin_transaction() returned false
* @since 19/May/14 support for PHP 5.4 using query('BEGIN')
*/
public function begin()
{
if ($this->bol_in_transaction) {
return $this;
}
if (!$this->obj_db->begin_transaction()) {
throw new \Exception("Failed to start a transaction");

if (PHP_VERSION_ID >= 50500) {
$bol_success = $this->obj_db->begin_transaction();
} else {
$bol_success = $this->obj_db->query('BEGIN');
}
$this->bol_in_transaction = true;

if ($bol_success) {
$this->bol_in_transaction = true;
} else {
throw new \Exception("Failed to start a transaction");
}

return $this;
}

Expand Down

0 comments on commit 9730f54

Please sign in to comment.