From 2a657fd987839148015eca5ea8b76df2d1f1ecf2 Mon Sep 17 00:00:00 2001 From: Adrian Hardy Date: Mon, 19 May 2014 10:46:27 +0100 Subject: [PATCH 1/2] Support transactions in PHP 5.4 by making sure begin() delegates to query('BEGIN') if begin_transaction() is not available. --- src/Docnet/DB.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Docnet/DB.php b/src/Docnet/DB.php index 40c1aef..ebd51e9 100644 --- a/src/Docnet/DB.php +++ b/src/Docnet/DB.php @@ -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 (version_compare(PHP_VERSION, '5.5.0') >= 0) { + $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; } From 8f05d9171478eef2b631e209257f616589fb1ace Mon Sep 17 00:00:00 2001 From: Adrian Hardy Date: Wed, 30 Jul 2014 16:45:40 +0100 Subject: [PATCH 2/2] Used the PHP_VERSION_ID constant to comapre, instead of version_compare() --- src/Docnet/DB.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Docnet/DB.php b/src/Docnet/DB.php index ebd51e9..ae85c1f 100644 --- a/src/Docnet/DB.php +++ b/src/Docnet/DB.php @@ -70,7 +70,7 @@ public function begin() return $this; } - if (version_compare(PHP_VERSION, '5.5.0') >= 0) { + if (PHP_VERSION_ID >= 50500) { $bol_success = $this->obj_db->begin_transaction(); } else { $bol_success = $this->obj_db->query('BEGIN');