Merge pull request #4369 from galdiolo/patch-12

Optimize transactions check in CI_DB_driver::query()
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index bfe9dd4..40e40e9 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -676,19 +676,15 @@
 				// if transactions are enabled. If we don't call this here
 				// the error message will trigger an exit, causing the
 				// transactions to remain in limbo.
-				if ($this->_trans_depth !== 0)
+				while ($this->_trans_depth !== 0)
 				{
-					do
+					$trans_depth = $this->_trans_depth;
+					$this->trans_complete();
+					if ($trans_depth === $this->_trans_depth)
 					{
-						$trans_depth = $this->_trans_depth;
-						$this->trans_complete();
-						if ($trans_depth === $this->_trans_depth)
-						{
-							log_message('error', 'Database: Failure during an automated transaction commit/rollback!');
-							break;
-						}
+						log_message('error', 'Database: Failure during an automated transaction commit/rollback!');
+						break;
 					}
-					while ($this->_trans_depth !== 0);
 				}
 
 				// Display errors