From e49b22c0de68ab13d41c9e2160584fe8964cff46 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Thu, 7 Oct 2010 13:54:05 +0200 Subject: [PATCH] Add XDB::startTransaction(), XDB::commit() and XDB::rollback(). Note: you should always use these functions when using transactions since they perform the necessary post/pre actions to ensure the environment is well configured. Signed-off-by: Florent Bruneau --- classes/xdb.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/classes/xdb.php b/classes/xdb.php index 2265e41..28010c9 100644 --- a/classes/xdb.php +++ b/classes/xdb.php @@ -86,7 +86,7 @@ class XDB if ($globals->debug & DEBUG_BT) { $explain = array(); - if (strpos($query, 'FOUND_ROWS()') === false) { + if (strpos($query, 'FOUND_ROWS()') === false && strpos($query, 'AUTOCOMMIT') === false) { $res = self::$mysqli->query("EXPLAIN $query"); if ($res) { while ($row = $res->fetch_assoc()) { @@ -194,6 +194,24 @@ class XDB return self::run($query); } + public static function startTransaction() + { + self::rawExecute('SET AUTOCOMMIT = 0'); + self::rawExecute('START TRANSACTION'); + } + + public static function commit() + { + self::rawExecute('COMMIT'); + self::rawExecute('SET AUTOCOMMIT = 1'); + } + + public static function rollback() + { + self::rawExecute('ROLLBACK'); + self::rawExecute('SET AUTOCOMMIT = 1'); + } + public static function iterator() { return new XDBIterator(self::prepare(func_get_args())); -- 2.1.4