summaryrefslogtreecommitdiffstats
path: root/system/database/DB_driver.php
diff options
context:
space:
mode:
authorDerek Allard <derek.allard@ellislab.com>2008-02-11 06:54:44 +0100
committerDerek Allard <derek.allard@ellislab.com>2008-02-11 06:54:44 +0100
commitc0743381b20910a3fc23b391e8b2009ac5771ae8 (patch)
treed456d728a363a11f3b634a128fcbf5fb61331d64 /system/database/DB_driver.php
parent70529a739dd0a73fc72124720390313d8a8b0dca (diff)
database enhancements, compatibility additions and bugfixes
Diffstat (limited to 'system/database/DB_driver.php')
-rw-r--r--system/database/DB_driver.php28
1 files changed, 18 insertions, 10 deletions
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;
}
// --------------------------------------------------------------------