summaryrefslogtreecommitdiffstats
path: root/system/database/DB_driver.php
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-06-12 13:16:53 +0200
committerAndrey Andreev <narf@bofh.bg>2012-06-12 13:16:53 +0200
commit4e9538fe19b09c0dc588542cfb7f793348b83bf7 (patch)
tree8466951d2e0b48b7d8de366fd4a72ca45563f428 /system/database/DB_driver.php
parentcce918033a99186cd76019d022571a8d9321d899 (diff)
Fix issue #145
Diffstat (limited to 'system/database/DB_driver.php')
-rw-r--r--system/database/DB_driver.php26
1 files changed, 9 insertions, 17 deletions
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;
}
// --------------------------------------------------------------------