From c0743381b20910a3fc23b391e8b2009ac5771ae8 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 11 Feb 2008 05:54:44 +0000 Subject: database enhancements, compatibility additions and bugfixes --- system/database/DB_driver.php | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'system/database/DB_driver.php') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 966fd3ad5..6b3a74b94 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -556,8 +556,8 @@ class CI_DB_driver { * @return string */ function compile_binds($sql, $binds) - { - if (FALSE === strpos($sql, $this->bind_marker)) + { + if (strpos($sql, $this->bind_marker) === FALSE) { return $sql; } @@ -567,17 +567,25 @@ class CI_DB_driver { $binds = array($binds); } - foreach ($binds as $val) + // 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)) { + $binds = array_slice($binds, 0, count($segments)-1); + } + + // Construct the binded query + $result = $segments[0]; + $i = 0; + foreach ($binds as $bind) { - $val = $this->escape($val); - - // Just in case the replacement string contains the bind - // character we'll temporarily replace it with a marker - $val = str_replace($this->bind_marker, '{%bind_marker%}', $val); - $sql = preg_replace("#".preg_quote($this->bind_marker, '#')."#", str_replace('$', '\$', $val), $sql, 1); + $result .= $this->escape($bind); + $result .= $segments[++$i]; } - return str_replace('{%bind_marker%}', $this->bind_marker, $sql); + return $result; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b