Thomas Bruederli
2012-11-17 be9aacaa5296dfca63fb3a01c2dc52538d1546aa
program/include/rcube_db.php
@@ -21,15 +21,16 @@
/**
 * Database independent query interface
 * Database independent query interface.
 * This is a wrapper for the PHP PDO.
 *
 * This is a wrapper for the PHP PDO
 *
 * @package Database
 * @version 1.0
 * @package   Framework
 * @sbpackage Database
 */
class rcube_db
{
    public $db_provider;
    protected $db_dsnw;               // DSN for write operations
    protected $db_dsnr;               // DSN for read operations
    protected $db_connected = false;  // Already connected ?
@@ -268,15 +269,15 @@
     *
     * @param int $res_id Optional query result identifier
     *
     * @return boolean True on error, False otherwise
     * @return string Error message
     */
    public function is_error($res_id = null)
    {
        if ($res_id !== null) {
            return $this->_get_result($res_id) === false;
            return $this->_get_result($res_id) === false ? $this->db_error_msg : null;
        }
        return $this->db_error;
        return $this->db_error ? $this->db_error_msg : null;
    }
    /**
@@ -388,13 +389,19 @@
        $idx = 0;
        while ($pos = strpos($query, '?', $pos)) {
            $val = $this->quote($params[$idx++]);
            unset($params[$idx-1]);
            $query = substr_replace($query, $val, $pos, 1);
            $pos += strlen($val);
            if ($query[$pos+1] == '?') {  // skip escaped ?
                $pos += 2;
            }
            else {
                $val = $this->quote($params[$idx++]);
                unset($params[$idx-1]);
                $query = substr_replace($query, $val, $pos, 1);
                $pos += strlen($val);
            }
        }
        $query = rtrim($query, ';');
        // replace escaped ? back to normal
        $query = rtrim(strtr($query, array('??' => '?')), ';');
        $this->debug($query);
@@ -576,6 +583,10 @@
            return intval($input);
        }
        if (is_null($input)) {
            return 'NULL';
        }
        // create DB handle if not available
        if (!$this->dbh) {
            $this->db_connect('r');
@@ -587,7 +598,7 @@
                'integer' => PDO::PARAM_INT,
            );
            $type = isset($map[$type]) ? $map[$type] : PDO::PARAM_STR;
            return $this->dbh->quote($input, $type);
            return strtr($this->dbh->quote($input, $type), array('?' => '??'));  // escape ?
        }
        return 'NULL';