From 4e9538fe19b09c0dc588542cfb7f793348b83bf7 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 12 Jun 2012 14:16:53 +0300 Subject: Fix issue #145 --- system/database/DB_driver.php | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 079ee8d05..88a3b388f 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -596,35 +596,27 @@ abstract class CI_DB_driver { */ public function compile_binds($sql, $binds) { - if (strpos($sql, $this->bind_marker) === FALSE) + if (preg_match_all('/(>|<|=|!)\s*('.preg_quote($this->bind_marker).')/i', $sql, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE) !== count($binds)) { return $sql; } - - if ( ! is_array($binds)) + elseif ( ! is_array($binds)) { $binds = array($binds); } - - // Get the sql segments around the bind markers - $segments = explode($this->bind_marker, $sql); - - // The count of bind should be 1 less then the count of segments - // If there are more bind arguments trim it down - if (count($binds) >= count($segments)) + else { - $binds = array_slice($binds, 0, count($segments)-1); + // Make sure we're using numeric keys + $binds = array_values($binds); } - // Construct the binded query - $result = $segments[0]; - $i = 0; - foreach ($binds as $bind) + + for ($i = count($matches) - 1; $i >= 0; $i--) { - $result .= $this->escape($bind).$segments[++$i]; + $sql = substr_replace($sql, $this->escape($binds[$i]), $matches[$i][2][1], 1); } - return $result; + return $sql; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b