Index: tmp/version-2_5-test/data/module/DB/ibase.php
===================================================================
--- tmp/version-2_5-test/data/module/DB/ibase.php	(revision 15532)
+++ tmp/version-2_5-test/data/module/DB/ibase.php	(revision 18609)
@@ -22,5 +22,5 @@
  * @author     Sterling Hughes <sterling@php.net>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  * @version    CVS: $Id$
@@ -48,7 +48,7 @@
  * @author     Sterling Hughes <sterling@php.net>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
- * @version    Release: @package_version@
+ * @version    Release: 1.7.14RC1
  * @link       http://pear.php.net/package/DB
  * @since      Class became stable in Release 1.7.0
@@ -124,4 +124,5 @@
         -803 => DB_ERROR_CONSTRAINT,
         -804 => DB_ERROR_VALUE_COUNT_ON_ROW,
+        // -902 =>  // Covers too many errors, need to use regex on msg
         -904 => DB_ERROR_CONNECT_FAILED,
         -922 => DB_ERROR_NOSUCHDB,
@@ -276,5 +277,5 @@
     function simpleQuery($query)
     {
-        $ismanip = DB::isManip($query);
+        $ismanip = $this->_checkManip($query);
         $this->last_query = $query;
         $query = $this->modifyQuery($query);
@@ -413,5 +414,5 @@
     function freeResult($result)
     {
-        return @ibase_free_result($result);
+        return is_resource($result) ? ibase_free_result($result) : false;
     }
 
@@ -421,6 +422,5 @@
     function freeQuery($query)
     {
-        @ibase_free_query($query);
-        return true;
+        return is_resource($query) ? ibase_free_query($query) : false;
     }
 
@@ -522,6 +522,12 @@
         $newquery = $this->modifyQuery($newquery);
         $stmt = @ibase_prepare($this->connection, $newquery);
-        $this->prepare_types[(int)$stmt] = $types;
-        $this->manip_query[(int)$stmt]   = DB::isManip($query);
+
+        if ($stmt === false) {
+            $stmt = $this->ibaseRaiseError();
+        } else {
+            $this->prepare_types[(int)$stmt] = $types;
+            $this->manip_query[(int)$stmt]   = DB::isManip($query);
+        }
+
         return $stmt;
     }
@@ -548,7 +554,7 @@
         $this->last_parameters = $data;
 
-        $types =& $this->prepare_types[(int)$stmt];
+        $types = $this->prepare_types[(int)$stmt];
         if (count($types) != count($data)) {
-            $tmp =& $this->raiseError(DB_ERROR_MISMATCH);
+            $tmp = $this->raiseError(DB_ERROR_MISMATCH);
             return $tmp;
         }
@@ -569,5 +575,5 @@
                 $fp = @fopen($data[$key], 'rb');
                 if (!$fp) {
-                    $tmp =& $this->raiseError(DB_ERROR_ACCESS_VIOLATION);
+                    $tmp = $this->raiseError(DB_ERROR_ACCESS_VIOLATION);
                     return $tmp;
                 }
@@ -582,5 +588,5 @@
         $res = call_user_func_array('ibase_execute', $data);
         if (!$res) {
-            $tmp =& $this->ibaseRaiseError();
+            $tmp = $this->ibaseRaiseError();
             return $tmp;
         }
@@ -590,8 +596,11 @@
         }*/
         $this->last_stmt = $stmt;
-        if ($this->manip_query[(int)$stmt]) {
+        if ($this->manip_query[(int)$stmt] || $this->_next_query_manip) {
+            $this->_last_query_manip = true;
+            $this->_next_query_manip = false;
             $tmp = DB_OK;
         } else {
-            $tmp =& new DB_result($this, $res);
+            $this->_last_query_manip = false;
+            $tmp = new DB_result($this, $res);
         }
         return $tmp;
@@ -699,5 +708,5 @@
         do {
             $this->pushErrorHandling(PEAR_ERROR_RETURN);
-            $result =& $this->query("SELECT GEN_ID(${sqn}, 1) "
+            $result = $this->query("SELECT GEN_ID(${sqn}, 1) "
                                    . 'FROM RDB$GENERATORS '
                                    . "WHERE RDB\$GENERATOR_NAME='${sqn}'");
@@ -857,5 +866,5 @@
             $errno = $this->errorCode($this->errorNative());
         }
-        $tmp =& $this->raiseError($errno, null, null, null, @ibase_errmsg());
+        $tmp = $this->raiseError($errno, null, null, null, @ibase_errmsg());
         return $tmp;
     }
@@ -926,4 +935,6 @@
                 '/arithmetic exception, numeric overflow, or string truncation/i'
                     => DB_ERROR_INVALID,
+                '/feature is not supported/i'
+                    => DB_ERROR_NOT_CAPABLE,
             );
         }
Index: tmp/version-2_5-test/data/module/DB/storage.php
===================================================================
--- tmp/version-2_5-test/data/module/DB/storage.php	(revision 15532)
+++ tmp/version-2_5-test/data/module/DB/storage.php	(revision 18609)
@@ -17,5 +17,5 @@
  * @package    DB
  * @author     Stig Bakken <stig@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  * @version    CVS: $Id$
@@ -37,7 +37,7 @@
  * @package    DB
  * @author     Stig Bakken <stig@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
- * @version    Release: @package_version@
+ * @version    Release: 1.7.14RC1
  * @link       http://pear.php.net/package/DB
  */
@@ -294,5 +294,5 @@
     {
         $classname = strtolower(get_class($this));
-        $obj =& new $classname($table);
+        $obj = new $classname($table);
         foreach ($data as $name => $value) {
             $obj->_properties[$name] = true;
@@ -446,4 +446,6 @@
     function store()
     {
+        $params = array();
+        $vars = array();
         foreach ($this->_changes as $name => $foo) {
             $params[] = &$this->$name;
Index: tmp/version-2_5-test/data/module/DB/mysql.php
===================================================================
--- tmp/version-2_5-test/data/module/DB/mysql.php	(revision 15532)
+++ tmp/version-2_5-test/data/module/DB/mysql.php	(revision 18609)
@@ -19,5 +19,5 @@
  * @author     Stig Bakken <ssb@php.net>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  * @version    CVS: $Id$
@@ -40,7 +40,7 @@
  * @author     Stig Bakken <ssb@php.net>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
- * @version    Release: @package_version@
+ * @version    Release: 1.7.14RC1
  * @link       http://pear.php.net/package/DB
  */
@@ -112,4 +112,7 @@
         1216 => DB_ERROR_CONSTRAINT,
         1217 => DB_ERROR_CONSTRAINT,
+        1356 => DB_ERROR_DIVZERO,
+        1451 => DB_ERROR_CONSTRAINT,
+        1452 => DB_ERROR_CONSTRAINT,
     );
 
@@ -237,8 +240,8 @@
                                                       $params);
         } else {
-            ini_set('track_errors', 1);
+            @ini_set('track_errors', 1);
             $this->connection = @call_user_func_array($connect_function,
                                                       $params);
-            ini_set('track_errors', $ini);
+            @ini_set('track_errors', $ini);
         }
 
@@ -298,5 +301,5 @@
     function simpleQuery($query)
     {
-        $ismanip = DB::isManip($query);
+        $ismanip = $this->_checkManip($query);
         $this->last_query = $query;
         $query = $this->modifyQuery($query);
@@ -420,5 +423,5 @@
     function freeResult($result)
     {
-        return @mysql_free_result($result);
+        return is_resource($result) ? mysql_free_result($result) : false;
     }
 
@@ -556,5 +559,5 @@
     function affectedRows()
     {
-        if (DB::isManip($this->last_query)) {
+        if ($this->_last_query_manip) {
             return @mysql_affected_rows($this->connection);
         } else {
@@ -753,7 +756,8 @@
     /**
      * Quotes a string so it can be safely used as a table or column name
-     *
-     * MySQL can't handle the backtick character (<kbd>`</kbd>) in
-     * table or column names.
+     * (WARNING: using names that require this is a REALLY BAD IDEA)
+     *
+     * WARNING:  Older versions of MySQL can't handle the backtick
+     * character (<kbd>`</kbd>) in table or column names.
      *
      * @param string $str  identifier name to be quoted
@@ -766,5 +770,5 @@
     function quoteIdentifier($str)
     {
-        return '`' . $str . '`';
+        return '`' . str_replace('`', '``', $str) . '`';
     }
 
@@ -853,5 +857,5 @@
     function modifyLimitQuery($query, $from, $count, $params = array())
     {
-        if (DB::isManip($query)) {
+        if (DB::isManip($query) || $this->_next_query_manip) {
             return $query . " LIMIT $count";
         } else {
@@ -929,10 +933,17 @@
     {
         if (is_string($result)) {
+            // Fix for bug #11580.
+            if ($this->_db) {
+                if (!@mysql_select_db($this->_db, $this->connection)) {
+                    return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
+                }
+            }
+            
             /*
              * Probably received a table name.
              * Create a result resource identifier.
              */
-            $id = @mysql_list_fields($this->dsn['database'],
-                                     $result, $this->connection);
+            $id = @mysql_query("SELECT * FROM $result LIMIT 0",
+                               $this->connection);
             $got_string = true;
         } elseif (isset($result->result)) {
Index: tmp/version-2_5-test/data/module/DB/ifx.php
===================================================================
--- tmp/version-2_5-test/data/module/DB/ifx.php	(revision 15532)
+++ tmp/version-2_5-test/data/module/DB/ifx.php	(revision 18609)
@@ -19,5 +19,5 @@
  * @author     Tomas V.V.Cox <cox@idecnet.com>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  * @version    CVS: $Id$
@@ -47,7 +47,7 @@
  * @author     Tomas V.V.Cox <cox@idecnet.com>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
- * @version    Release: @package_version@
+ * @version    Release: 1.7.14RC1
  * @link       http://pear.php.net/package/DB
  */
@@ -102,4 +102,5 @@
         '-239'    => DB_ERROR_CONSTRAINT,
         '-253'    => DB_ERROR_SYNTAX,
+        '-268'    => DB_ERROR_CONSTRAINT,
         '-292'    => DB_ERROR_CONSTRAINT_NOT_NULL,
         '-310'    => DB_ERROR_ALREADY_EXISTS,
@@ -114,4 +115,5 @@
         '-692'    => DB_ERROR_CONSTRAINT,
         '-703'    => DB_ERROR_CONSTRAINT_NOT_NULL,
+        '-1202'   => DB_ERROR_DIVZERO,
         '-1204'   => DB_ERROR_INVALID_DATE,
         '-1205'   => DB_ERROR_INVALID_DATE,
@@ -244,8 +246,8 @@
     function simpleQuery($query)
     {
-        $ismanip = DB::isManip($query);
+        $ismanip = $this->_checkManip($query);
         $this->last_query = $query;
         $this->affected   = null;
-        if (preg_match('/(SELECT)/i', $query)) {    //TESTME: Use !DB::isManip()?
+        if (preg_match('/(SELECT|EXECUTE)/i', $query)) {    //TESTME: Use !DB::isManip()?
             // the scroll is needed for fetching absolute row numbers
             // in a select query result
@@ -269,5 +271,5 @@
         // Determine which queries should return data, and which
         // should return an error code only.
-        if (preg_match('/(SELECT)/i', $query)) {
+        if (preg_match('/(SELECT|EXECUTE)/i', $query)) {
             return $result;
         }
@@ -310,5 +312,5 @@
     function affectedRows()
     {
-        if (DB::isManip($this->last_query)) {
+        if ($this->_last_query_manip) {
             return $this->affected;
         } else {
@@ -421,5 +423,5 @@
     function freeResult($result)
     {
-        return @ifx_free_result($result);
+        return is_resource($result) ? ifx_free_result($result) : false;
     }
 
Index: tmp/version-2_5-test/data/module/DB/pgsql.php
===================================================================
--- tmp/version-2_5-test/data/module/DB/pgsql.php	(revision 15532)
+++ tmp/version-2_5-test/data/module/DB/pgsql.php	(revision 18609)
@@ -20,5 +20,5 @@
  * @author     Stig Bakken <ssb@php.net>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  * @version    CVS: $Id$
@@ -29,5 +29,4 @@
  * Obtain the DB_common class so it can be extended from
  */
- 
 require_once DB_PHP_DIR . '/DB/common.php';
 
@@ -43,7 +42,7 @@
  * @author     Stig Bakken <ssb@php.net>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
- * @version    Release: @package_version@
+ * @version    Release: 1.7.14RC1
  * @link       http://pear.php.net/package/DB
  */
@@ -195,5 +194,5 @@
      * );
      * 
-     * $db =& DB::connect($dsn, $options);
+     * $db = DB::connect($dsn, $options);
      * if (PEAR::isError($db)) {
      *     die($db->getMessage());
@@ -279,8 +278,8 @@
                                                       $params);
         } else {
-            ini_set('track_errors', 1);
+            @ini_set('track_errors', 1);
             $this->connection = @call_user_func_array($connect_function,
                                                       $params);
-            ini_set('track_errors', $ini);
+            @ini_set('track_errors', $ini);
         }
 
@@ -322,5 +321,5 @@
     function simpleQuery($query)
     {
-        $ismanip = DB::isManip($query);
+        $ismanip = $this->_checkManip($query);
         $this->last_query = $query;
         $query = $this->modifyQuery($query);
@@ -338,17 +337,24 @@
             return $this->pgsqlRaiseError();
         }
-        // Determine which queries that should return data, and which
-        // should return an error code only.
+
+        /*
+         * Determine whether queries produce affected rows, result or nothing.
+         *
+         * This logic was introduced in version 1.1 of the file by ssb,
+         * though the regex has been modified slightly since then.
+         *
+         * PostgreSQL commands:
+         * ABORT, ALTER, BEGIN, CLOSE, CLUSTER, COMMIT, COPY,
+         * CREATE, DECLARE, DELETE, DROP TABLE, EXPLAIN, FETCH,
+         * GRANT, INSERT, LISTEN, LOAD, LOCK, MOVE, NOTIFY, RESET,
+         * REVOKE, ROLLBACK, SELECT, SELECT INTO, SET, SHOW,
+         * UNLISTEN, UPDATE, VACUUM
+         */
         if ($ismanip) {
             $this->affected = @pg_affected_rows($result);
             return DB_OK;
-        } elseif (preg_match('/^\s*\(*\s*(SELECT|EXPLAIN|SHOW)\s/si', $query)) {
-            /* PostgreSQL commands:
-               ABORT, ALTER, BEGIN, CLOSE, CLUSTER, COMMIT, COPY,
-               CREATE, DECLARE, DELETE, DROP TABLE, EXPLAIN, FETCH,
-               GRANT, INSERT, LISTEN, LOAD, LOCK, MOVE, NOTIFY, RESET,
-               REVOKE, ROLLBACK, SELECT, SELECT INTO, SET, SHOW,
-               UNLISTEN, UPDATE, VACUUM
-            */
+        } elseif (preg_match('/^\s*\(*\s*(SELECT|EXPLAIN|FETCH|SHOW)\s/si',
+                             $query))
+        {
             $this->row[(int)$result] = 0; // reset the row counter.
             $numrows = $this->numRows($result);
@@ -473,58 +479,52 @@
 
     // }}}
-    // {{{ quoteSmart()
-
-    /**
-     * Formats input so it can be safely used in a query
-     *
-     * @param mixed $in  the data to be formatted
-     *
-     * @return mixed  the formatted data.  The format depends on the input's
-     *                 PHP type:
-     *                 + null = the string <samp>NULL</samp>
-     *                 + boolean = string <samp>TRUE</samp> or <samp>FALSE</samp>
-     *                 + integer or double = the unquoted number
-     *                 + other (including strings and numeric strings) =
-     *                   the data escaped according to MySQL's settings
-     *                   then encapsulated between single quotes
+    // {{{ quoteBoolean()
+
+    /**
+     * Formats a boolean value for use within a query in a locale-independent
+     * manner.
+     *
+     * @param boolean the boolean value to be quoted.
+     * @return string the quoted string.
+     * @see DB_common::quoteSmart()
+     * @since Method available since release 1.7.8.
+     */
+    function quoteBoolean($boolean) {
+        return $boolean ? 'TRUE' : 'FALSE';
+    }
+     
+    // }}}
+    // {{{ escapeSimple()
+
+    /**
+     * Escapes a string according to the current DBMS's standards
+     *
+     * {@internal PostgreSQL treats a backslash as an escape character,
+     * so they are escaped as well.
+     *
+     * @param string $str  the string to be escaped
+     *
+     * @return string  the escaped string
      *
      * @see DB_common::quoteSmart()
      * @since Method available since Release 1.6.0
      */
-    function quoteSmart($in)
-    {
-        if (is_int($in) || is_double($in)) {
-            return $in;
-        } elseif (is_bool($in)) {
-            return $in ? 'TRUE' : 'FALSE';
-        } elseif (is_null($in)) {
-            return 'NULL';
+    function escapeSimple($str)
+    {
+        if (function_exists('pg_escape_string')) {
+            /* This fixes an undocumented BC break in PHP 5.2.0 which changed
+             * the prototype of pg_escape_string. I'm not thrilled about having
+             * to sniff the PHP version, quite frankly, but it's the only way
+             * to deal with the problem. Revision 1.331.2.13.2.10 on
+             * php-src/ext/pgsql/pgsql.c (PHP_5_2 branch) is to blame, for the
+             * record. */
+            if (version_compare(PHP_VERSION, '5.2.0', '>=')) {
+                return pg_escape_string($this->connection, $str);
+            } else {
+                return pg_escape_string($str);
+            }
         } else {
-            return "'" . $this->escapeSimple($in) . "'";
-        }
-    }
-
-    // }}}
-    // {{{ escapeSimple()
-
-    /**
-     * Escapes a string according to the current DBMS's standards
-     *
-     * {@internal PostgreSQL treats a backslash as an escape character,
-     * so they are escaped as well.
-     *
-     * Not using pg_escape_string() yet because it requires PostgreSQL
-     * to be at version 7.2 or greater.}}
-     *
-     * @param string $str  the string to be escaped
-     *
-     * @return string  the escaped string
-     *
-     * @see DB_common::quoteSmart()
-     * @since Method available since Release 1.6.0
-     */
-    function escapeSimple($str)
-    {
-        return str_replace("'", "''", str_replace('\\', '\\\\', $str));
+            return str_replace("'", "''", str_replace('\\', '\\\\', $str));
+        }
     }
 
@@ -677,5 +677,5 @@
         do {
             $this->pushErrorHandling(PEAR_ERROR_RETURN);
-            $result =& $this->query("SELECT NEXTVAL('${seqname}')");
+            $result = $this->query("SELECT NEXTVAL('${seqname}')");
             $this->popErrorHandling();
             if ($ondemand && DB::isError($result) &&
@@ -781,4 +781,8 @@
     {
         $native = $this->errorNative();
+        if (!$native) {
+            $native = 'Database connection has been lost.';
+            $errno = DB_ERROR_CONNECT_FAILED;
+        }
         if ($errno === null) {
             $errno = $this->errorCode($native);
@@ -817,10 +821,10 @@
         if (!isset($error_regexps)) {
             $error_regexps = array(
+                '/column .* (of relation .*)?does not exist/i'
+                    => DB_ERROR_NOSUCHFIELD,
                 '/(relation|sequence|table).*does not exist|class .* not found/i'
                     => DB_ERROR_NOSUCHTABLE,
                 '/index .* does not exist/'
                     => DB_ERROR_NOT_FOUND,
-                '/column .* does not exist/i'
-                    => DB_ERROR_NOSUCHFIELD,
                 '/relation .* already exists/i'
                     => DB_ERROR_ALREADY_EXISTS,
@@ -978,10 +982,21 @@
         $field_name = @pg_fieldname($resource, $num_field);
 
+        // Check if there's a schema in $table_name and update things
+        // accordingly.
+        $from = 'pg_attribute f, pg_class tab, pg_type typ';
+        if (strpos($table_name, '.') !== false) {
+            $from .= ', pg_namespace nsp';
+            list($schema, $table) = explode('.', $table_name);
+            $tableWhere = "tab.relname = '$table' AND tab.relnamespace = nsp.oid AND nsp.nspname = '$schema'";
+        } else {
+            $tableWhere = "tab.relname = '$table_name'";
+        }
+
         $result = @pg_exec($this->connection, "SELECT f.attnotnull, f.atthasdef
-                                FROM pg_attribute f, pg_class tab, pg_type typ
+                                FROM $from
                                 WHERE tab.relname = typ.typname
                                 AND typ.typrelid = f.attrelid
                                 AND f.attname = '$field_name'
-                                AND tab.relname = '$table_name'");
+                                AND $tableWhere");
         if (@pg_numrows($result) > 0) {
             $row = @pg_fetch_row($result, 0);
@@ -990,8 +1005,8 @@
             if ($row[1] == 't') {
                 $result = @pg_exec($this->connection, "SELECT a.adsrc
-                                    FROM pg_attribute f, pg_class tab, pg_type typ, pg_attrdef a
+                                    FROM $from, pg_attrdef a
                                     WHERE tab.relname = typ.typname AND typ.typrelid = f.attrelid
                                     AND f.attrelid = a.adrelid AND f.attname = '$field_name'
-                                    AND tab.relname = '$table_name' AND f.attnum = a.adnum");
+                                    AND $tableWhere AND f.attnum = a.adnum");
                 $row = @pg_fetch_row($result, 0);
                 $num = preg_replace("/'(.*)'::\w+/", "\\1", $row[0]);
@@ -1002,10 +1017,10 @@
         }
         $result = @pg_exec($this->connection, "SELECT i.indisunique, i.indisprimary, i.indkey
-                                FROM pg_attribute f, pg_class tab, pg_type typ, pg_index i
+                                FROM $from, pg_index i
                                 WHERE tab.relname = typ.typname
                                 AND typ.typrelid = f.attrelid
                                 AND f.attrelid = i.indrelid
                                 AND f.attname = '$field_name'
-                                AND tab.relname = '$table_name'");
+                                AND $tableWhere");
         $count = @pg_numrows($result);
 
@@ -1068,4 +1083,7 @@
                         . ' WHERE schemaname NOT IN'
                         . " ('pg_catalog', 'information_schema', 'pg_toast')";
+            case 'schema.views':
+                return "SELECT schemaname || '.' || viewname from pg_views WHERE schemaname"
+                        . " NOT IN ('information_schema', 'pg_catalog')";
             case 'views':
                 // Table cols: viewname | viewowner | definition
@@ -1086,4 +1104,23 @@
 
     // }}}
+    // {{{ _checkManip()
+
+    /**
+     * Checks if the given query is a manipulation query. This also takes into
+     * account the _next_query_manip flag and sets the _last_query_manip flag
+     * (and resets _next_query_manip) according to the result.
+     *
+     * @param string The query to check.
+     *
+     * @return boolean true if the query is a manipulation query, false
+     * otherwise
+     *
+     * @access protected
+     */
+    function _checkManip($query)
+    {
+        return (preg_match('/^\s*(SAVEPOINT|RELEASE)\s+/i', $query)
+                || parent::_checkManip($query));
+    }
 
 }
Index: tmp/version-2_5-test/data/module/DB/sybase.php
===================================================================
--- tmp/version-2_5-test/data/module/DB/sybase.php	(revision 15532)
+++ tmp/version-2_5-test/data/module/DB/sybase.php	(revision 18609)
@@ -18,7 +18,7 @@
  * @package    DB
  * @author     Sterling Hughes <sterling@php.net>
- * @author     Ant?io Carlos Ven?cio J?ior <floripa@php.net>
+ * @author     Antônio Carlos Venâncio Júnior <floripa@php.net>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  * @version    CVS: $Id$
@@ -43,9 +43,9 @@
  * @package    DB
  * @author     Sterling Hughes <sterling@php.net>
- * @author     Ant?io Carlos Ven?cio J?ior <floripa@php.net>
+ * @author     Antônio Carlos Venâncio Júnior <floripa@php.net>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
- * @version    Release: @package_version@
+ * @version    Release: 1.7.14RC1
  * @link       http://pear.php.net/package/DB
  */
@@ -249,7 +249,7 @@
     function simpleQuery($query)
     {
-        $ismanip = DB::isManip($query);
+        $ismanip = $this->_checkManip($query);
         $this->last_query = $query;
-        if (!@sybase_select_db($this->_db, $this->connection)) {
+        if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) {
             return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
         }
@@ -371,5 +371,5 @@
     function freeResult($result)
     {
-        return @sybase_free_result($result);
+        return is_resource($result) ? sybase_free_result($result) : false;
     }
 
@@ -436,5 +436,5 @@
     function affectedRows()
     {
-        if (DB::isManip($this->last_query)) {
+        if ($this->_last_query_manip) {
             $result = @sybase_affected_rows($this->connection);
         } else {
@@ -463,5 +463,5 @@
     {
         $seqname = $this->getSequenceName($seq_name);
-        if (!@sybase_select_db($this->_db, $this->connection)) {
+        if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) {
             return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
         }
@@ -480,5 +480,5 @@
                 }
             } elseif (!DB::isError($result)) {
-                $result =& $this->query("SELECT @@IDENTITY FROM $seqname");
+                $result = $this->query("SELECT @@IDENTITY FROM $seqname");
                 $repeat = 0;
             } else {
@@ -530,4 +530,20 @@
 
     // }}}
+    // {{{ quoteFloat()
+
+    /**
+     * Formats a float value for use within a query in a locale-independent
+     * manner.
+     *
+     * @param float the float value to be quoted.
+     * @return string the quoted string.
+     * @see DB_common::quoteSmart()
+     * @since Method available since release 1.7.8.
+     */
+    function quoteFloat($float) {
+        return $this->escapeSimple(str_replace(',', '.', strval(floatval($float))));
+    }
+     
+    // }}}
     // {{{ autoCommit()
 
@@ -559,5 +575,5 @@
     {
         if ($this->transaction_opcount > 0) {
-            if (!@sybase_select_db($this->_db, $this->connection)) {
+            if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) {
                 return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
             }
@@ -582,5 +598,5 @@
     {
         if ($this->transaction_opcount > 0) {
-            if (!@sybase_select_db($this->_db, $this->connection)) {
+            if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) {
                 return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
             }
@@ -643,4 +659,9 @@
     {
         static $error_regexps;
+        
+        // PHP 5.2+ prepends the function name to $php_errormsg, so we need
+        // this hack to work around it, per bug #9599.
+        $errormsg = preg_replace('/^sybase[a-z_]+\(\): /', '', $errormsg);
+        
         if (!isset($error_regexps)) {
             $error_regexps = array(
@@ -675,4 +696,6 @@
                 '/^There are fewer columns in the INSERT statement than values specified/i'
                     => DB_ERROR_VALUE_COUNT_ON_ROW,
+                '/Divide by zero/i'
+                    => DB_ERROR_DIVZERO,
             );
         }
@@ -715,5 +738,5 @@
              * Create a result resource identifier.
              */
-            if (!@sybase_select_db($this->_db, $this->connection)) {
+            if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) {
                 return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
             }
@@ -812,12 +835,22 @@
             $tableName = $table;
 
-            // get unique/primary keys
-            $res = $this->getAll("sp_helpindex $table", DB_FETCHMODE_ASSOC);
-
-            if (!isset($res[0]['index_description'])) {
+            /* We're running sp_helpindex directly because it doesn't exist in
+             * older versions of ASE -- unfortunately, we can't just use
+             * DB::isError() because the user may be using callback error
+             * handling. */
+            $res = @sybase_query("sp_helpindex $table", $this->connection);
+
+            if ($res === false || $res === true) {
+                // Fake a valid response for BC reasons.
                 return '';
             }
 
-            foreach ($res as $val) {
+            while (($val = sybase_fetch_assoc($res)) !== false) {
+                if (!isset($val['index_keys'])) {
+                    /* No useful information returned. Break and be done with
+                     * it, which preserves the pre-1.7.9 behaviour. */
+                    break;
+                }
+
                 $keys = explode(', ', trim($val['index_keys']));
 
@@ -834,4 +867,6 @@
                 }
             }
+
+            sybase_free_result($res);
 
         }
Index: tmp/version-2_5-test/data/module/DB/fbsql.php
===================================================================
--- tmp/version-2_5-test/data/module/DB/fbsql.php	(revision 15532)
+++ tmp/version-2_5-test/data/module/DB/fbsql.php	(revision 18609)
@@ -19,5 +19,5 @@
  * @author     Frank M. Kromann <frank@frontbase.com>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  * @version    CVS: $Id$
@@ -40,7 +40,7 @@
  * @author     Frank M. Kromann <frank@frontbase.com>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
- * @version    Release: @package_version@
+ * @version    Release: 1.7.14RC1
  * @link       http://pear.php.net/package/DB
  * @since      Class functional since Release 1.7.0
@@ -172,8 +172,8 @@
                                                       $params);
         } else {
-            ini_set('track_errors', 1);
+            @ini_set('track_errors', 1);
             $this->connection = @call_user_func_array($connect_function,
                                                       $params);
-            ini_set('track_errors', $ini);
+            @ini_set('track_errors', $ini);
         }
 
@@ -230,5 +230,5 @@
         // Determine which queries that should return data, and which
         // should return an error code only.
-        if (DB::isManip($query)) {
+        if ($this->_checkManip($query)) {
             return DB_OK;
         }
@@ -321,5 +321,5 @@
     function freeResult($result)
     {
-        return @fbsql_free_result($result);
+        return is_resource($result) ? fbsql_free_result($result) : false;
     }
 
@@ -354,5 +354,5 @@
     function commit()
     {
-        @fbsql_commit();
+        @fbsql_commit($this->connection);
     }
 
@@ -367,5 +367,5 @@
     function rollback()
     {
-        @fbsql_rollback();
+        @fbsql_rollback($this->connection);
     }
 
@@ -432,5 +432,5 @@
     function affectedRows()
     {
-        if (DB::isManip($this->last_query)) {
+        if ($this->_last_query_manip) {
             $result = @fbsql_affected_rows($this->connection);
         } else {
@@ -544,5 +544,5 @@
     function modifyLimitQuery($query, $from, $count, $params = array())
     {
-        if (DB::isManip($query)) {
+        if (DB::isManip($query) || $this->_next_query_manip) {
             return preg_replace('/^([\s(])*SELECT/i',
                                 "\\1SELECT TOP($count)", $query);
@@ -554,36 +554,35 @@
 
     // }}}
-    // {{{ quoteSmart()
-
-    /**
-     * Formats input so it can be safely used in a query
-     *
-     * @param mixed $in  the data to be formatted
-     *
-     * @return mixed  the formatted data.  The format depends on the input's
-     *                 PHP type:
-     *                 + null = the string <samp>NULL</samp>
-     *                 + boolean = string <samp>TRUE</samp> or <samp>FALSE</samp>
-     *                 + integer or double = the unquoted number
-     *                 + other (including strings and numeric strings) =
-     *                   the data escaped according to FrontBase's settings
-     *                   then encapsulated between single quotes
-     *
+    // {{{ quoteBoolean()
+
+    /**
+     * Formats a boolean value for use within a query in a locale-independent
+     * manner.
+     *
+     * @param boolean the boolean value to be quoted.
+     * @return string the quoted string.
      * @see DB_common::quoteSmart()
-     * @since Method available since Release 1.6.0
-     */
-    function quoteSmart($in)
-    {
-        if (is_int($in) || is_double($in)) {
-            return $in;
-        } elseif (is_bool($in)) {
-            return $in ? 'TRUE' : 'FALSE';
-        } elseif (is_null($in)) {
-            return 'NULL';
-        } else {
-            return "'" . $this->escapeSimple($in) . "'";
-        }
-    }
-
+     * @since Method available since release 1.7.8.
+     */
+    function quoteBoolean($boolean) {
+        return $boolean ? 'TRUE' : 'FALSE';
+    }
+     
+    // }}}
+    // {{{ quoteFloat()
+
+    /**
+     * Formats a float value for use within a query in a locale-independent
+     * manner.
+     *
+     * @param float the float value to be quoted.
+     * @return string the quoted string.
+     * @see DB_common::quoteSmart()
+     * @since Method available since release 1.7.8.
+     */
+    function quoteFloat($float) {
+        return $this->escapeSimple(str_replace(',', '.', strval(floatval($float))));
+    }
+     
     // }}}
     // {{{ fbsqlRaiseError()
Index: tmp/version-2_5-test/data/module/DB/odbc.php
===================================================================
--- tmp/version-2_5-test/data/module/DB/odbc.php	(revision 15532)
+++ tmp/version-2_5-test/data/module/DB/odbc.php	(revision 18609)
@@ -19,5 +19,5 @@
  * @author     Stig Bakken <ssb@php.net>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  * @version    CVS: $Id$
@@ -43,7 +43,7 @@
  * @author     Stig Bakken <ssb@php.net>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
- * @version    Release: @package_version@
+ * @version    Release: 1.7.14RC1
  * @link       http://pear.php.net/package/DB
  */
@@ -267,5 +267,5 @@
         // Determine which queries that should return data, and which
         // should return an error code only.
-        if (DB::isManip($query)) {
+        if ($this->_checkManip($query)) {
             $this->affected = $result; // For affectedRows()
             return DB_OK;
@@ -368,5 +368,5 @@
     function freeResult($result)
     {
-        return @odbc_free_result($result);
+        return is_resource($result) ? odbc_free_result($result) : false;
     }
 
Index: tmp/version-2_5-test/data/module/DB/common.php
===================================================================
--- tmp/version-2_5-test/data/module/DB/common.php	(revision 15532)
+++ tmp/version-2_5-test/data/module/DB/common.php	(revision 18609)
@@ -19,5 +19,5 @@
  * @author     Tomas V.V. Cox <cox@idecnet.com>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  * @version    CVS: $Id$
@@ -41,7 +41,7 @@
  * @author     Tomas V.V. Cox <cox@idecnet.com>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
- * @version    Release: @package_version@
+ * @version    Release: 1.7.14RC1
  * @link       http://pear.php.net/package/DB
  */
@@ -121,4 +121,19 @@
      */
     var $prepared_queries = array();
+
+    /**
+     * Flag indicating that the last query was a manipulation query.
+     * @access protected
+     * @var boolean
+     */
+    var $_last_query_manip = false;
+
+    /**
+     * Flag indicating that the next query <em>must</em> be a manipulation
+     * query.
+     * @access protected
+     * @var boolean
+     */
+    var $_next_query_manip = false;
 
 
@@ -425,15 +440,54 @@
     function quoteSmart($in)
     {
-        if (is_int($in) || is_double($in)) {
+        if (is_int($in)) {
             return $in;
+        } elseif (is_float($in)) {
+            return $this->quoteFloat($in);
         } elseif (is_bool($in)) {
-            return $in ? 1 : 0;
+            return $this->quoteBoolean($in);
         } elseif (is_null($in)) {
             return 'NULL';
         } else {
+            if ($this->dbsyntax == 'access'
+                && preg_match('/^#.+#$/', $in))
+            {
+                return $this->escapeSimple($in);
+            }
             return "'" . $this->escapeSimple($in) . "'";
         }
     }
 
+    // }}}
+    // {{{ quoteBoolean()
+
+    /**
+     * Formats a boolean value for use within a query in a locale-independent
+     * manner.
+     *
+     * @param boolean the boolean value to be quoted.
+     * @return string the quoted string.
+     * @see DB_common::quoteSmart()
+     * @since Method available since release 1.7.8.
+     */
+    function quoteBoolean($boolean) {
+        return $boolean ? '1' : '0';
+    }
+     
+    // }}}
+    // {{{ quoteFloat()
+
+    /**
+     * Formats a float value for use within a query in a locale-independent
+     * manner.
+     *
+     * @param float the float value to be quoted.
+     * @return string the quoted string.
+     * @see DB_common::quoteSmart()
+     * @since Method available since release 1.7.8.
+     */
+    function quoteFloat($float) {
+        return "'".$this->escapeSimple(str_replace(',', '.', strval(floatval($float))))."'";
+    }
+     
     // }}}
     // {{{ escapeSimple()
@@ -838,5 +892,5 @@
             return $sth;
         }
-        $ret =& $this->execute($sth, array_values($fields_values));
+        $ret = $this->execute($sth, array_values($fields_values));
         $this->freePrepared($sth);
         return $ret;
@@ -932,5 +986,5 @@
      *     'filename.txt'
      * );
-     * $res =& $db->execute($sth, $data);
+     * $res = $db->execute($sth, $data);
      * </code>
      *
@@ -952,5 +1006,4 @@
     function &execute($stmt, $data = array())
     {
-
         $realquery = $this->executeEmulateQuery($stmt, $data);
         if (DB::isError($realquery)) {
@@ -962,5 +1015,5 @@
             return $result;
         } else {
-            $tmp =& new DB_result($this, $result);
+            $tmp = new DB_result($this, $result);
             return $tmp;
         }
@@ -991,5 +1044,5 @@
         $data = (array)$data;
         $this->last_parameters = $data;
-	
+
         if (count($this->prepare_types[$stmt]) != count($data)) {
             $this->last_query = $this->prepared_queries[$stmt];
@@ -1002,9 +1055,9 @@
         foreach ($data as $value) {
             if ($this->prepare_types[$stmt][$i] == DB_PARAM_SCALAR) {
-				if ($value != "") {
-					$realquery .= $this->quoteSmart($value);
-				}else{
-					$realquery .= 'NULL';
-				}
+                if (strlen($value) == 0) {
+                    $realquery .= 'NULL';
+                } else {
+                    $realquery .= $this->quoteSmart($value);
+                }
             } elseif ($this->prepare_types[$stmt][$i] == DB_PARAM_OPAQUE) {
                 $fp = @fopen($value, 'rb');
@@ -1047,5 +1100,5 @@
     {
         foreach ($data as $value) {
-            $res =& $this->execute($stmt, $value);
+            $res = $this->execute($stmt, $value);
             if (DB::isError($res)) {
                 return $res;
@@ -1160,5 +1213,5 @@
                 return $sth;
             }
-            $ret =& $this->execute($sth, $params);
+            $ret = $this->execute($sth, $params);
             $this->freePrepared($sth, false);
             return $ret;
@@ -1169,5 +1222,5 @@
                 return $result;
             } else {
-                $tmp =& new DB_result($this, $result);
+                $tmp = new DB_result($this, $result);
                 return $tmp;
             }
@@ -1200,5 +1253,5 @@
             return $query;
         }
-        $result =& $this->query($query, $params);
+        $result = $this->query($query, $params);
         if (is_a($result, 'DB_result')) {
             $result->setOption('limit_from', $from);
@@ -1235,8 +1288,8 @@
                 return $sth;
             }
-            $res =& $this->execute($sth, $params);
+            $res = $this->execute($sth, $params);
             $this->freePrepared($sth);
         } else {
-            $res =& $this->query($query);
+            $res = $this->query($query);
         }
 
@@ -1299,8 +1352,8 @@
                 return $sth;
             }
-            $res =& $this->execute($sth, $params);
+            $res = $this->execute($sth, $params);
             $this->freePrepared($sth);
         } else {
-            $res =& $this->query($query);
+            $res = $this->query($query);
         }
 
@@ -1350,8 +1403,8 @@
             }
 
-            $res =& $this->execute($sth, $params);
+            $res = $this->execute($sth, $params);
             $this->freePrepared($sth);
         } else {
-            $res =& $this->query($query);
+            $res = $this->query($query);
         }
 
@@ -1366,5 +1419,5 @@
         } else {
             if (!array_key_exists($col, $row)) {
-                $ret =& $this->raiseError(DB_ERROR_NOSUCHFIELD);
+                $ret = $this->raiseError(DB_ERROR_NOSUCHFIELD);
             } else {
                 $ret = array($row[$col]);
@@ -1482,8 +1535,8 @@
             }
 
-            $res =& $this->execute($sth, $params);
+            $res = $this->execute($sth, $params);
             $this->freePrepared($sth);
         } else {
-            $res =& $this->query($query);
+            $res = $this->query($query);
         }
 
@@ -1497,5 +1550,5 @@
 
         if ($cols < 2) {
-            $tmp =& $this->raiseError(DB_ERROR_TRUNCATED);
+            $tmp = $this->raiseError(DB_ERROR_TRUNCATED);
             return $tmp;
         }
@@ -1601,4 +1654,5 @@
             }
         }
+
         if (sizeof($params) > 0) {
             $sth = $this->prepare($query);
@@ -1608,8 +1662,8 @@
             }
 
-            $res =& $this->execute($sth, $params);
+            $res = $this->execute($sth, $params);
             $this->freePrepared($sth);
         } else {
-            $res =& $this->query($query);
+            $res = $this->query($query);
         }
 
@@ -1632,5 +1686,5 @@
 
         if (DB::isError($row)) {
-            $tmp =& $this->raiseError($row);
+            $tmp = $this->raiseError($row);
             return $tmp;
         }
@@ -1819,4 +1873,8 @@
      * @param mixed   native error code, integer or string depending the
      *                 backend
+     * @param mixed   dummy parameter for E_STRICT compatibility with
+     *                 PEAR::raiseError
+     * @param mixed   dummy parameter for E_STRICT compatibility with
+     *                 PEAR::raiseError
      *
      * @return object  the PEAR_Error object
@@ -1825,5 +1883,6 @@
      */
     function &raiseError($code = DB_ERROR, $mode = null, $options = null,
-                         $userinfo = null, $nativecode = null)
+                         $userinfo = null, $nativecode = null, $dummy1 = null,
+                         $dummy2 = null)
     {
         // The error is yet a DB error object
@@ -2108,4 +2167,50 @@
 
     // }}}
+    // {{{ nextQueryIsManip()
+
+    /**
+     * Sets (or unsets) a flag indicating that the next query will be a
+     * manipulation query, regardless of the usual DB::isManip() heuristics.
+     *
+     * @param boolean true to set the flag overriding the isManip() behaviour,
+     * false to clear it and fall back onto isManip()
+     *
+     * @return void
+     *
+     * @access public
+     */
+    function nextQueryIsManip($manip)
+    {
+        $this->_next_query_manip = $manip;
+    }
+
+    // }}}
+    // {{{ _checkManip()
+
+    /**
+     * Checks if the given query is a manipulation query. This also takes into
+     * account the _next_query_manip flag and sets the _last_query_manip flag
+     * (and resets _next_query_manip) according to the result.
+     *
+     * @param string The query to check.
+     *
+     * @return boolean true if the query is a manipulation query, false
+     * otherwise
+     *
+     * @access protected
+     */
+    function _checkManip($query)
+    {
+        if ($this->_next_query_manip || DB::isManip($query)) {
+            $this->_last_query_manip = true;
+        } else {
+            $this->_last_query_manip = false;
+        }
+        $this->_next_query_manip = false;
+        return $this->_last_query_manip;
+        $manip = $this->_next_query_manip;
+    }
+
+    // }}}
     // {{{ _rtrimArrayValues()
 
Index: tmp/version-2_5-test/data/module/DB/msql.php
===================================================================
--- tmp/version-2_5-test/data/module/DB/msql.php	(revision 15532)
+++ tmp/version-2_5-test/data/module/DB/msql.php	(revision 18609)
@@ -22,5 +22,5 @@
  * @package    DB
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  * @version    CVS: $Id$
@@ -46,7 +46,7 @@
  * @package    DB
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
- * @version    Release: @package_version@
+ * @version    Release: 1.7.14RC1
  * @link       http://pear.php.net/package/DB
  * @since      Class not functional until Release 1.7.0
@@ -154,5 +154,5 @@
      * );
      * 
-     * $db =& DB::connect($dsn, $options);
+     * $db = DB::connect($dsn, $options);
      * if (PEAR::isError($db)) {
      *     die($db->getMessage());
@@ -191,8 +191,8 @@
                                                       $params);
         } else {
-            ini_set('track_errors', 1);
+            @ini_set('track_errors', 1);
             $this->connection = @call_user_func_array($connect_function,
                                                       $params);
-            ini_set('track_errors', $ini);
+            @ini_set('track_errors', $ini);
         }
 
@@ -252,5 +252,5 @@
         // Determine which queries that should return data, and which
         // should return an error code only.
-        if (DB::isManip($query)) {
+        if ($this->_checkManip($query)) {
             $this->_result = $result;
             return DB_OK;
@@ -351,5 +351,5 @@
     function freeResult($result)
     {
-        return @msql_free_result($result);
+        return is_resource($result) ? msql_free_result($result) : false;
     }
 
@@ -444,5 +444,5 @@
         do {
             $this->pushErrorHandling(PEAR_ERROR_RETURN);
-            $result =& $this->query("SELECT _seq FROM ${seqname}");
+            $result = $this->query("SELECT _seq FROM ${seqname}");
             $this->popErrorHandling();
             if ($ondemand && DB::isError($result) &&
@@ -532,4 +532,20 @@
 
     // }}}
+    // {{{ quoteFloat()
+
+    /**
+     * Formats a float value for use within a query in a locale-independent
+     * manner.
+     *
+     * @param float the float value to be quoted.
+     * @return string the quoted string.
+     * @see DB_common::quoteSmart()
+     * @since Method available since release 1.7.8.
+     */
+    function quoteFloat($float) {
+        return $this->escapeSimple(str_replace(',', '.', strval(floatval($float))));
+    }
+     
+    // }}}
     // {{{ escapeSimple()
 
@@ -599,4 +615,9 @@
     {
         static $error_regexps;
+        
+        // PHP 5.2+ prepends the function name to $php_errormsg, so we need
+        // this hack to work around it, per bug #9599.
+        $errormsg = preg_replace('/^msql[a-z_]+\(\): /', '', $errormsg);
+
         if (!isset($error_regexps)) {
             $error_regexps = array(
Index: tmp/version-2_5-test/data/module/DB/dbase.php
===================================================================
--- tmp/version-2_5-test/data/module/DB/dbase.php	(revision 15532)
+++ tmp/version-2_5-test/data/module/DB/dbase.php	(revision 18609)
@@ -19,5 +19,5 @@
  * @author     Tomas V.V. Cox <cox@idecnet.com>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  * @version    CVS: $Id$
@@ -40,7 +40,7 @@
  * @author     Tomas V.V. Cox <cox@idecnet.com>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
- * @version    Release: @package_version@
+ * @version    Release: 1.7.14RC1
  * @link       http://pear.php.net/package/DB
  */
@@ -189,5 +189,5 @@
      * );
      *
-     * $db =& DB::connect($dsn, $options);
+     * $db = DB::connect($dsn, $options);
      * if (PEAR::isError($db)) {
      *     die($db->getMessage());
@@ -215,5 +215,5 @@
          * is the only way to find errors from the dbase extension.
          */
-        ini_set('track_errors', 1);
+        @ini_set('track_errors', 1);
         $php_errormsg = '';
 
@@ -274,5 +274,5 @@
         // emulate result resources
         $this->res_row[(int)$this->result] = 0;
-        $tmp =& new DB_result($this, $this->result++);
+        $tmp = new DB_result($this, $this->result++);
         return $tmp;
     }
@@ -327,4 +327,24 @@
 
     // }}}
+    // {{{ freeResult()
+
+    /**
+     * Deletes the result set and frees the memory occupied by the result set.
+     *
+     * This method is a no-op for dbase, as there aren't result resources in
+     * the same sense as most other database backends.
+     *
+     * @param resource $result  PHP's query result resource
+     *
+     * @return bool  TRUE on success, FALSE if $result is invalid
+     *
+     * @see DB_result::free()
+     */
+    function freeResult($result)
+    {
+        return true;
+    }
+
+    // }}}
     // {{{ numCols()
 
@@ -369,39 +389,19 @@
 
     // }}}
-    // {{{ quoteSmart()
-
-    /**
-     * Formats input so it can be safely used in a query
-     *
-     * @param mixed $in  the data to be formatted
-     *
-     * @return mixed  the formatted data.  The format depends on the input's
-     *                 PHP type:
-     *                 + null = the string <samp>NULL</samp>
-     *                 + boolean = <samp>T</samp> if true or
-     *                   <samp>F</samp> if false.  Use the <kbd>Logical</kbd>
-     *                   data type.
-     *                 + integer or double = the unquoted number
-     *                 + other (including strings and numeric strings) =
-     *                   the data with single quotes escaped by preceeding
-     *                   single quotes then the whole string is encapsulated
-     *                   between single quotes
-     *
+    // {{{ quoteBoolean()
+
+    /**
+     * Formats a boolean value for use within a query in a locale-independent
+     * manner.
+     *
+     * @param boolean the boolean value to be quoted.
+     * @return string the quoted string.
      * @see DB_common::quoteSmart()
-     * @since Method available since Release 1.6.0
-     */
-    function quoteSmart($in)
-    {
-        if (is_int($in) || is_double($in)) {
-            return $in;
-        } elseif (is_bool($in)) {
-            return $in ? 'T' : 'F';
-        } elseif (is_null($in)) {
-            return 'NULL';
-        } else {
-            return "'" . $this->escapeSimple($in) . "'";
-        }
-    }
-
+     * @since Method available since release 1.7.8.
+     */
+    function quoteBoolean($boolean) {
+        return $boolean ? 'T' : 'F';
+    }
+     
     // }}}
     // {{{ tableInfo()
Index: tmp/version-2_5-test/data/module/DB/mysqli.php
===================================================================
--- tmp/version-2_5-test/data/module/DB/mysqli.php	(revision 15532)
+++ tmp/version-2_5-test/data/module/DB/mysqli.php	(revision 18609)
@@ -18,5 +18,5 @@
  * @package    DB
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  * @version    CVS: $Id$
@@ -42,7 +42,7 @@
  * @package    DB
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
- * @version    Release: @package_version@
+ * @version    Release: 1.7.14RC1
  * @link       http://pear.php.net/package/DB
  * @since      Class functional since Release 1.6.3
@@ -115,4 +115,7 @@
         1216 => DB_ERROR_CONSTRAINT,
         1217 => DB_ERROR_CONSTRAINT,
+        1356 => DB_ERROR_DIVZERO,
+        1451 => DB_ERROR_CONSTRAINT,
+        1452 => DB_ERROR_CONSTRAINT,
     );
 
@@ -211,4 +214,8 @@
         MYSQLI_TYPE_STRING      => 'char',
         MYSQLI_TYPE_GEOMETRY    => 'geometry',
+        /* These constants are conditionally compiled in ext/mysqli, so we'll
+         * define them by number rather than constant. */
+        16                      => 'bit',
+        246                     => 'decimal',
     );
 
@@ -265,5 +272,5 @@
      * );
      * 
-     * $db =& DB::connect($dsn, $options);
+     * $db = DB::connect($dsn, $options);
      * if (PEAR::isError($db)) {
      *     die($db->getMessage());
@@ -288,8 +295,8 @@
 
         $ini = ini_get('track_errors');
-        ini_set('track_errors', 1);
+        @ini_set('track_errors', 1);
         $php_errormsg = '';
 
-        if ($this->getOption('ssl') === true) {
+        if (((int) $this->getOption('ssl')) === 1) {
             $init = mysqli_init();
             mysqli_ssl_set(
@@ -323,5 +330,5 @@
         }
 
-        ini_set('track_errors', $ini);
+        @ini_set('track_errors', $ini);
 
         if (!$this->connection) {
@@ -373,5 +380,5 @@
     function simpleQuery($query)
     {
-        $ismanip = DB::isManip($query);
+        $ismanip = $this->_checkManip($query);
         $this->last_query = $query;
         $query = $this->modifyQuery($query);
@@ -491,5 +498,5 @@
     function freeResult($result)
     {
-        return @mysqli_free_result($result);
+        return is_resource($result) ? mysqli_free_result($result) : false;
     }
 
@@ -627,5 +634,5 @@
     function affectedRows()
     {
-        if (DB::isManip($this->last_query)) {
+        if ($this->_last_query_manip) {
             return @mysqli_affected_rows($this->connection);
         } else {
@@ -824,7 +831,8 @@
     /**
      * Quotes a string so it can be safely used as a table or column name
-     *
-     * MySQL can't handle the backtick character (<kbd>`</kbd>) in
-     * table or column names.
+     * (WARNING: using names that require this is a REALLY BAD IDEA)
+     *
+     * WARNING:  Older versions of MySQL can't handle the backtick
+     * character (<kbd>`</kbd>) in table or column names.
      *
      * @param string $str  identifier name to be quoted
@@ -837,5 +845,5 @@
     function quoteIdentifier($str)
     {
-        return '`' . $str . '`';
+        return '`' . str_replace('`', '``', $str) . '`';
     }
 
@@ -879,5 +887,5 @@
     function modifyLimitQuery($query, $from, $count, $params = array())
     {
-        if (DB::isManip($query)) {
+        if (DB::isManip($query) || $this->_next_query_manip) {
             return $query . " LIMIT $count";
         } else {
@@ -955,4 +963,11 @@
     {
         if (is_string($result)) {
+            // Fix for bug #11580.
+            if ($this->_db) {
+                if (!@mysqli_select_db($this->connection, $this->_db)) {
+                    return $this->mysqliRaiseError(DB_ERROR_NODBSELECTED);
+                }
+            }
+
             /*
              * Probably received a table name.
@@ -1016,5 +1031,6 @@
                                     ? $this->mysqli_types[$tmp->type]
                                     : 'unknown',
-                'len'   => $tmp->max_length,
+                // http://bugs.php.net/?id=36579
+                'len'   => $tmp->length,
                 'flags' => $flags,
             );
Index: tmp/version-2_5-test/data/module/DB/mssql.php
===================================================================
--- tmp/version-2_5-test/data/module/DB/mssql.php	(revision 15532)
+++ tmp/version-2_5-test/data/module/DB/mssql.php	(revision 18609)
@@ -19,5 +19,5 @@
  * @author     Sterling Hughes <sterling@php.net>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  * @version    CVS: $Id$
@@ -36,11 +36,19 @@
  * These methods overload the ones declared in DB_common.
  *
+ * DB's mssql driver is only for Microsfoft SQL Server databases.
+ *
+ * If you're connecting to a Sybase database, you MUST specify "sybase"
+ * as the "phptype" in the DSN.
+ *
+ * This class only works correctly if you have compiled PHP using
+ * --with-mssql=[dir_to_FreeTDS].
+ *
  * @category   Database
  * @package    DB
  * @author     Sterling Hughes <sterling@php.net>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
- * @version    Release: @package_version@
+ * @version    Release: 1.7.14RC1
  * @link       http://pear.php.net/package/DB
  */
@@ -90,17 +98,38 @@
     // XXX Add here error codes ie: 'S100E' => DB_ERROR_SYNTAX
     var $errorcode_map = array(
+        102   => DB_ERROR_SYNTAX,
         110   => DB_ERROR_VALUE_COUNT_ON_ROW,
         155   => DB_ERROR_NOSUCHFIELD,
+        156   => DB_ERROR_SYNTAX,
         170   => DB_ERROR_SYNTAX,
         207   => DB_ERROR_NOSUCHFIELD,
         208   => DB_ERROR_NOSUCHTABLE,
         245   => DB_ERROR_INVALID_NUMBER,
+        319   => DB_ERROR_SYNTAX,
+        321   => DB_ERROR_NOSUCHFIELD,
+        325   => DB_ERROR_SYNTAX,
+        336   => DB_ERROR_SYNTAX,
         515   => DB_ERROR_CONSTRAINT_NOT_NULL,
         547   => DB_ERROR_CONSTRAINT,
+        1018  => DB_ERROR_SYNTAX,
+        1035  => DB_ERROR_SYNTAX,
         1913  => DB_ERROR_ALREADY_EXISTS,
+        2209  => DB_ERROR_SYNTAX,
+        2223  => DB_ERROR_SYNTAX,
+        2248  => DB_ERROR_SYNTAX,
+        2256  => DB_ERROR_SYNTAX,
+        2257  => DB_ERROR_SYNTAX,
         2627  => DB_ERROR_CONSTRAINT,
         2714  => DB_ERROR_ALREADY_EXISTS,
+        3607  => DB_ERROR_DIVZERO,
         3701  => DB_ERROR_NOSUCHTABLE,
+        7630  => DB_ERROR_SYNTAX,
         8134  => DB_ERROR_DIVZERO,
+        9303  => DB_ERROR_SYNTAX,
+        9317  => DB_ERROR_SYNTAX,
+        9318  => DB_ERROR_SYNTAX,
+        9331  => DB_ERROR_SYNTAX,
+        9332  => DB_ERROR_SYNTAX,
+        15253 => DB_ERROR_SYNTAX,
     );
 
@@ -245,5 +274,5 @@
     function simpleQuery($query)
     {
-        $ismanip = DB::isManip($query);
+        $ismanip = $this->_checkManip($query);
         $this->last_query = $query;
         if (!@mssql_select_db($this->_db, $this->connection)) {
@@ -317,5 +346,5 @@
         }
         if ($fetchmode & DB_FETCHMODE_ASSOC) {
-            $arr = @mssql_fetch_array($result, MSSQL_ASSOC);
+            $arr = @mssql_fetch_assoc($result);
             if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
                 $arr = array_change_key_case($arr, CASE_LOWER);
@@ -354,5 +383,5 @@
     function freeResult($result)
     {
-        return @mssql_free_result($result);
+        return is_resource($result) ? mssql_free_result($result) : false;
     }
 
@@ -484,5 +513,5 @@
     function affectedRows()
     {
-        if (DB::isManip($this->last_query)) {
+        if ($this->_last_query_manip) {
             $res = @mssql_query('select @@rowcount', $this->connection);
             if (!$res) {
@@ -538,5 +567,13 @@
                 }
             } elseif (!DB::isError($result)) {
-                $result =& $this->query("SELECT @@IDENTITY FROM $seqname");
+                $result = $this->query("SELECT IDENT_CURRENT('$seqname')");
+                if (DB::isError($result)) {
+                    /* Fallback code for MS SQL Server 7.0, which doesn't have
+                     * IDENT_CURRENT. This is *not* safe for concurrent
+                     * requests, and really, if you're using it, you're in a
+                     * world of hurt. Nevertheless, it's here to ensure BC. See
+                     * bug #181 for the gory details.*/
+                    $result = $this->query("SELECT @@IDENTITY FROM $seqname");
+                }
                 $repeat = 0;
             } else {
@@ -746,4 +783,14 @@
 
         for ($i = 0; $i < $count; $i++) {
+            if ($got_string) {
+                $flags = $this->_mssql_field_flags($result,
+                        @mssql_field_name($id, $i));
+                if (DB::isError($flags)) {
+                    return $flags;
+                }
+            } else {
+                $flags = '';
+            }
+
             $res[$i] = array(
                 'table' => $got_string ? $case_func($result) : '',
@@ -751,9 +798,5 @@
                 'type'  => @mssql_field_type($id, $i),
                 'len'   => @mssql_field_length($id, $i),
-                // We only support flags for table
-                'flags' => $got_string
-                           ? $this->_mssql_field_flags($result,
-                                                       @mssql_field_name($id, $i))
-                           : '',
+                'flags' => $flags,
             );
             if ($mode & DB_TABLEINFO_ORDER) {
@@ -806,5 +849,8 @@
 
             // get unique and primary keys
-            $res = $this->getAll("EXEC SP_HELPINDEX[$table]", DB_FETCHMODE_ASSOC);
+            $res = $this->getAll("EXEC SP_HELPINDEX $table", DB_FETCHMODE_ASSOC);
+            if (DB::isError($res)) {
+                return $res;
+            }
 
             foreach ($res as $val) {
@@ -829,5 +875,8 @@
 
             // get auto_increment, not_null and timestamp
-            $res = $this->getAll("EXEC SP_COLUMNS[$table]", DB_FETCHMODE_ASSOC);
+            $res = $this->getAll("EXEC SP_COLUMNS $table", DB_FETCHMODE_ASSOC);
+            if (DB::isError($res)) {
+                return $res;
+            }
 
             foreach ($res as $val) {
Index: tmp/version-2_5-test/data/module/DB/sqlite.php
===================================================================
--- tmp/version-2_5-test/data/module/DB/sqlite.php	(revision 15532)
+++ tmp/version-2_5-test/data/module/DB/sqlite.php	(revision 18609)
@@ -20,5 +20,5 @@
  * @author     Mika Tuupola <tuupola@appelsiini.net>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 3.0
  * @version    CVS: $Id$
@@ -46,7 +46,7 @@
  * @author     Mika Tuupola <tuupola@appelsiini.net>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 3.0
- * @version    Release: @package_version@
+ * @version    Release: 1.7.14RC1
  * @link       http://pear.php.net/package/DB
  */
@@ -183,5 +183,5 @@
      * );
      * 
-     * $db =& DB::connect($dsn, $options);
+     * $db = DB::connect($dsn, $options);
      * if (PEAR::isError($db)) {
      *     die($db->getMessage());
@@ -205,5 +205,9 @@
         }
 
-        if ($dsn['database']) {
+        if (!$dsn['database']) {
+            return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION);
+        }
+
+        if ($dsn['database'] !== ':memory:') {
             if (!file_exists($dsn['database'])) {
                 if (!touch($dsn['database'])) {
@@ -230,6 +234,4 @@
                 return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION);
             }
-        } else {
-            return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION);
         }
 
@@ -237,5 +239,5 @@
 
         // track_errors must remain on for simpleQuery()
-        ini_set('track_errors', 1);
+        @ini_set('track_errors', 1);
         $php_errormsg = '';
 
@@ -281,5 +283,5 @@
     function simpleQuery($query)
     {
-        $ismanip = DB::isManip($query);
+        $ismanip = $this->_checkManip($query);
         $this->last_query = $query;
         $query = $this->modifyQuery($query);
@@ -357,4 +359,14 @@
             if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
                 $arr = array_change_key_case($arr, CASE_LOWER);
+            }
+
+            /* Remove extraneous " characters from the fields in the result.
+             * Fixes bug #11716. */
+            if (is_array($arr) && count($arr) > 0) {
+                $strippedArr = array();
+                foreach ($arr as $field => $value) {
+                    $strippedArr[trim($field, '"')] = $value;
+                }
+                $arr = $strippedArr;
             }
         } else {
@@ -728,4 +740,9 @@
     {
         static $error_regexps;
+        
+        // PHP 5.2+ prepends the function name to $php_errormsg, so we need
+        // this hack to work around it, per bug #9599.
+        $errormsg = preg_replace('/^sqlite[a-z_]+\(\): /', '', $errormsg);
+        
         if (!isset($error_regexps)) {
             $error_regexps = array(
@@ -739,4 +756,5 @@
                 '/may not be NULL/' => DB_ERROR_CONSTRAINT_NOT_NULL,
                 '/^no such column:/' => DB_ERROR_NOSUCHFIELD,
+                '/no column named/' => DB_ERROR_NOSUCHFIELD,
                 '/column not present in both tables/i' => DB_ERROR_NOSUCHFIELD,
                 '/^near ".*": syntax error$/' => DB_ERROR_SYNTAX,
Index: tmp/version-2_5-test/data/module/DB/oci8.php
===================================================================
--- tmp/version-2_5-test/data/module/DB/oci8.php	(revision 15532)
+++ tmp/version-2_5-test/data/module/DB/oci8.php	(revision 18609)
@@ -19,5 +19,5 @@
  * @author     James L. Pine <jlp@valinux.com>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  * @version    CVS: $Id$
@@ -46,7 +46,7 @@
  * @author     James L. Pine <jlp@valinux.com>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
- * @version    Release: @package_version@
+ * @version    Release: 1.7.14RC1
  * @link       http://pear.php.net/package/DB
  */
@@ -95,22 +95,23 @@
      */
     var $errorcode_map = array(
-        1    => DB_ERROR_CONSTRAINT,
-        900  => DB_ERROR_SYNTAX,
-        904  => DB_ERROR_NOSUCHFIELD,
-        913  => DB_ERROR_VALUE_COUNT_ON_ROW,
-        921  => DB_ERROR_SYNTAX,
-        923  => DB_ERROR_SYNTAX,
-        942  => DB_ERROR_NOSUCHTABLE,
-        955  => DB_ERROR_ALREADY_EXISTS,
-        1400 => DB_ERROR_CONSTRAINT_NOT_NULL,
-        1401 => DB_ERROR_INVALID,
-        1407 => DB_ERROR_CONSTRAINT_NOT_NULL,
-        1418 => DB_ERROR_NOT_FOUND,
-        1476 => DB_ERROR_DIVZERO,
-        1722 => DB_ERROR_INVALID_NUMBER,
-        2289 => DB_ERROR_NOSUCHTABLE,
-        2291 => DB_ERROR_CONSTRAINT,
-        2292 => DB_ERROR_CONSTRAINT,
-        2449 => DB_ERROR_CONSTRAINT,
+        1     => DB_ERROR_CONSTRAINT,
+        900   => DB_ERROR_SYNTAX,
+        904   => DB_ERROR_NOSUCHFIELD,
+        913   => DB_ERROR_VALUE_COUNT_ON_ROW,
+        921   => DB_ERROR_SYNTAX,
+        923   => DB_ERROR_SYNTAX,
+        942   => DB_ERROR_NOSUCHTABLE,
+        955   => DB_ERROR_ALREADY_EXISTS,
+        1400  => DB_ERROR_CONSTRAINT_NOT_NULL,
+        1401  => DB_ERROR_INVALID,
+        1407  => DB_ERROR_CONSTRAINT_NOT_NULL,
+        1418  => DB_ERROR_NOT_FOUND,
+        1476  => DB_ERROR_DIVZERO,
+        1722  => DB_ERROR_INVALID_NUMBER,
+        2289  => DB_ERROR_NOSUCHTABLE,
+        2291  => DB_ERROR_CONSTRAINT,
+        2292  => DB_ERROR_CONSTRAINT,
+        2449  => DB_ERROR_CONSTRAINT,
+        12899 => DB_ERROR_INVALID,
     );
 
@@ -160,4 +161,11 @@
      */
     var $manip_query = array();
+
+    /**
+     * Store of prepared SQL queries.
+     * @var array
+     * @access private
+     */
+    var $_prepared_queries = array();
 
 
@@ -217,4 +225,11 @@
         }
 
+        // Backwards compatibility with DB < 1.7.0
+        if (empty($dsn['database']) && !empty($dsn['hostspec'])) {
+            $db = $dsn['hostspec'];
+        } else {
+            $db = $dsn['database'];
+        }
+
         if (function_exists('oci_connect')) {
             if (isset($dsn['new_link'])
@@ -226,10 +241,6 @@
                                     : 'oci_connect';
             }
-
-            // Backwards compatibility with DB < 1.7.0
-            if (empty($dsn['database']) && !empty($dsn['hostspec'])) {
-                $db = $dsn['hostspec'];
-            } else {
-                $db = $dsn['database'];
+            if (isset($this->dsn['port']) && $this->dsn['port']) {
+                $db = '//'.$db.':'.$this->dsn['port'];
             }
 
@@ -249,8 +260,8 @@
         } else {
             $connect_function = $persistent ? 'OCIPLogon' : 'OCILogon';
-            if ($dsn['hostspec']) {
+            if ($db) {
                 $this->connection = @$connect_function($dsn['username'],
                                                        $dsn['password'],
-                                                       $dsn['hostspec']);
+                                                       $db);
             } elseif ($dsn['username'] || $dsn['password']) {
                 $this->connection = @$connect_function($dsn['username'],
@@ -323,5 +334,5 @@
         }
         $this->last_stmt = $result;
-        if (DB::isManip($query)) {
+        if ($this->_checkManip($query)) {
             return DB_OK;
         } else {
@@ -416,5 +427,5 @@
     function freeResult($result)
     {
-        return @OCIFreeStatement($result);
+        return is_resource($result) ? OCIFreeStatement($result) : false;
     }
 
@@ -477,18 +488,16 @@
             $save_stmt = $this->last_stmt;
 
-            if (count($this->_data)) {
-                $smt = $this->prepare('SELECT COUNT(*) FROM ('.$this->last_query.')');
-                $count = $this->execute($smt, $this->_data);
-            } else {
-                $count =& $this->query($countquery);
-            }
-
+            $count = $this->query($countquery);
+
+            // Restore the last query and statement.
+            $this->last_query = $save_query;
+            $this->last_stmt = $save_stmt;
+            
             if (DB::isError($count) ||
                 DB::isError($row = $count->fetchRow(DB_FETCHMODE_ORDERED)))
             {
-                $this->last_query = $save_query;
-                $this->last_stmt = $save_stmt;
                 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
             }
+
             return $row[0];
         }
@@ -591,4 +600,5 @@
         $this->prepare_types[(int)$stmt] = $types;
         $this->manip_query[(int)$stmt] = DB::isManip($query);
+        $this->_prepared_queries[(int)$stmt] = $newquery;
         return $stmt;
     }
@@ -621,9 +631,10 @@
         $data = (array)$data;
         $this->last_parameters = $data;
+        $this->last_query = $this->_prepared_queries[(int)$stmt];
         $this->_data = $data;
 
-        $types =& $this->prepare_types[(int)$stmt];
+        $types = $this->prepare_types[(int)$stmt];
         if (count($types) != count($data)) {
-            $tmp =& $this->raiseError(DB_ERROR_MISMATCH);
+            $tmp = $this->raiseError(DB_ERROR_MISMATCH);
             return $tmp;
         }
@@ -644,9 +655,15 @@
                 $fp = @fopen($data[$key], 'rb');
                 if (!$fp) {
-                    $tmp =& $this->raiseError(DB_ERROR_ACCESS_VIOLATION);
+                    $tmp = $this->raiseError(DB_ERROR_ACCESS_VIOLATION);
                     return $tmp;
                 }
                 $data[$key] = fread($fp, filesize($data[$key]));
                 fclose($fp);
+            } elseif ($types[$i] == DB_PARAM_SCALAR) {
+                // Floats have to be converted to a locale-neutral
+                // representation.
+                if (is_float($data[$key])) {
+                    $data[$key] = $this->quoteFloat($data[$key]);
+                }
             }
             if (!@OCIBindByName($stmt, ':bind' . $i, $data[$key], -1)) {
@@ -654,4 +671,5 @@
                 return $tmp;
             }
+            $this->last_query = preg_replace("/:bind$i/",$this->quoteSmart($data[$key]),$this->last_query,1);
             $i++;
         }
@@ -666,9 +684,12 @@
         }
         $this->last_stmt = $stmt;
-        if ($this->manip_query[(int)$stmt]) {
+        if ($this->manip_query[(int)$stmt] || $this->_next_query_manip) {
+            $this->_last_query_manip = true;
+            $this->_next_query_manip = false;
             $tmp = DB_OK;
         } else {
+            $this->_last_query_manip = false;
             @ocisetprefetch($stmt, $this->options['result_buffering']);
-            $tmp =& new DB_result($this, $stmt);
+            $tmp = new DB_result($this, $stmt);
         }
         return $tmp;
@@ -798,5 +819,5 @@
             $result = $this->prepare("SELECT * FROM ($query) "
                                      . 'WHERE NULL = NULL');
-            $tmp =& $this->execute($result, $params);
+            $tmp = $this->execute($result, $params);
         } else {
             $q_fields = "SELECT * FROM ($query) WHERE NULL = NULL";
@@ -858,5 +879,5 @@
         do {
             $this->expectError(DB_ERROR_NOSUCHTABLE);
-            $result =& $this->query("SELECT ${seqname}.nextval FROM dual");
+            $result = $this->query("SELECT ${seqname}.nextval FROM dual");
             $this->popExpect();
             if ($ondemand && DB::isError($result) &&
@@ -1016,5 +1037,5 @@
                 return $this->oci8RaiseError($stmt);
             }
-
+            
             $i = 0;
             while (@OCIFetch($stmt)) {
@@ -1099,4 +1120,6 @@
             case 'synonyms':
                 return 'SELECT synonym_name FROM user_synonyms';
+            case 'views':
+                return 'SELECT view_name FROM user_views';
             default:
                 return null;
@@ -1104,4 +1127,20 @@
     }
 
+    // }}}
+    // {{{ quoteFloat()
+
+    /**
+     * Formats a float value for use within a query in a locale-independent
+     * manner.
+     *
+     * @param float the float value to be quoted.
+     * @return string the quoted string.
+     * @see DB_common::quoteSmart()
+     * @since Method available since release 1.7.8.
+     */
+    function quoteFloat($float) {
+        return $this->escapeSimple(str_replace(',', '.', strval(floatval($float))));
+    }
+     
     // }}}
 
