database enhancements, compatibility additions and bugfixes
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 966fd3a..6b3a74b 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -556,8 +556,8 @@
 	 * @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 @@
 			$binds = array($binds);

 		}

 		

-		foreach ($binds as $val)

-		{

-			$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);

+		// 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);

 		}

 

-		return str_replace('{%bind_marker%}', $this->bind_marker, $sql);		

+		// Construct the binded query

+		$result = $segments[0];

+		$i = 0;

+		foreach ($binds as $bind)

+		{

+			$result .= $this->escape($bind);

+			$result .= $segments[++$i];

+		}

+

+		return $result;

 	}

 	

 	// --------------------------------------------------------------------

diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index 8e12a2d..7b024d4 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -408,9 +408,9 @@
 		// I don't believe this is necessary with MS SQL.  Not sure, though. - Rick

 	

 		/*

-		if (stristr($table, '.'))

+		if (strpos($table, '.') !== FALSE)

 		{

-			$table = preg_replace("/\./", "`.`", $table);

+			$table = '"' . str_replace('.', '"."', $table) . '"';

 		}

 		*/

 		

diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php
index 372365a..edf09a1 100644
--- a/system/database/drivers/mysql/mysql_driver.php
+++ b/system/database/drivers/mysql/mysql_driver.php
@@ -418,7 +418,7 @@
 	{

 		if (strpos($table, '.') !== FALSE)

 		{

-			$table = str_replace('.', '`.`', $table);

+			$table = '`' . str_replace('.', '`.`', $table) . '`';

 		}

 		

 		return $table;

diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php
index 31c2711..dab56c7 100644
--- a/system/database/drivers/mysqli/mysqli_driver.php
+++ b/system/database/drivers/mysqli/mysqli_driver.php
@@ -410,9 +410,9 @@
 	 */

 	function _escape_table($table)

 	{

-		if (stristr($table, '.'))

+		if (strpos($table, '.') !== FALSE)

 		{

-			$table = preg_replace("/\./", "`.`", $table);

+			$table = '`' . str_replace('.', '`.`', $table) . '`';

 		}

 		

 		return $table;

diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php
index 8f63c25..ec26f5b 100644
--- a/system/database/drivers/oci8/oci8_driver.php
+++ b/system/database/drivers/oci8/oci8_driver.php
@@ -521,9 +521,9 @@
 	 */

 	function _escape_table($table)

 	{

-		if (stristr($table, '.'))

+		if (strpos($table, '.') !== FALSE)

 		{

-			$table = preg_replace("/\./", "`.`", $table);

+			$table = '"' . str_replace('.', '"."', $table) . '"';

 		}

 

 		return $table;

diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index dd10fbd..fd24608 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -386,9 +386,9 @@
 	 */

 	function _escape_table($table)

 	{

-		if (stristr($table, '.'))

+		if (strpos($table, '.') !== FALSE)

 		{

-			$table = preg_replace("/\./", "`.`", $table);

+			$table = '`' . str_replace('.', '`.`', $table) . '`';

 		}

 		

 		return $table;

diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index a32c37e..ce8cb25 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -406,9 +406,9 @@
 	 */

 	function _escape_table($table)

 	{

-		if (stristr($table, '.'))

+		if (strpos($table, '.') !== FALSE)

 		{

-			$table = '"'.preg_replace("/\./", '"."', $table).'"';

+			$table = '"' . str_replace('.', '"."', $table) . '"';

 		}

 		

 		return $table;