| | |
| | | var $db_handle = 0; // Connection handle |
| | | var $db_error = false; |
| | | var $db_error_msg = ''; |
| | | var $debug_mode = false; |
| | | |
| | | var $a_query_results = array('dummy'); |
| | | var $last_res_id = 0; |
| | |
| | | function dsn_connect($dsn) |
| | | { |
| | | // Use persistent connections if available |
| | | $dbh = MDB2::connect($dsn, array('persistent' => $this->db_pconn, 'portability' => MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL)); |
| | | $dbh = MDB2::connect($dsn, array( |
| | | 'persistent' => $this->db_pconn, |
| | | 'emulate_prepared' => $this->debug_mode, |
| | | 'debug' => $this->debug_mode, |
| | | 'debug_handler' => 'mdb2_debug_handler', |
| | | 'portability' => MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL)); |
| | | |
| | | if (PEAR::isError($dbh)) |
| | | if (MDB2::isError($dbh)) |
| | | { |
| | | $this->db_error = TRUE; |
| | | $this->db_error_msg = $dbh->getMessage(); |
| | | |
| | | raise_error(array('code' => 500, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__, |
| | | 'message' => $dbh->getUserInfo()), TRUE, FALSE); |
| | | raise_error(array('code' => 500, 'type' => 'db', 'line' => __LINE__, |
| | | 'file' => __FILE__, 'message' => $dbh->getUserInfo()), TRUE, FALSE); |
| | | } |
| | | else if ($this->db_provider=='sqlite') |
| | | { |
| | |
| | | $this->db_connected = true; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Activate/deactivate debug mode |
| | | * |
| | | * @param boolean True if SQL queries should be logged |
| | | */ |
| | | function set_debug($dbg = true) |
| | | { |
| | | $this->debug_mode = $dbg; |
| | | if ($this->db_connected) |
| | | { |
| | | $this->db_handle->setOption('debug', $dbg); |
| | | $this->db_handle->setOption('emulate_prepared', $dbg); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | |
| | | return $this->db_handle->quoteIdentifier($str); |
| | | } |
| | | |
| | | /** |
| | | * Escapes a string |
| | | * |
| | | * @param string The string to be escaped |
| | | * @return string The escaped string |
| | | * @access public |
| | | * @since 0.1.1 |
| | | */ |
| | | function escapeSimple($str) |
| | | { |
| | | if (!$this->db_handle) |
| | | $this->db_connect('r'); |
| | | |
| | | return $this->db_handle->escape($str); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Return SQL function for current time and date |
| | |
| | | |
| | | } // end class rcube_db |
| | | |
| | | |
| | | /* this is our own debug handler for the MDB2 connection */ |
| | | function mdb2_debug_handler(&$db, $scope, $message, $context = array()) |
| | | { |
| | | if ($scope != 'prepare') |
| | | { |
| | | $debug_output = $scope . '('.$db->db_index.'): '; |
| | | $debug_output .= $message . $db->getOption('log_line_break'); |
| | | write_log('sqllog', $debug_output); |
| | | } |
| | | } |
| | | |
| | | |
| | | ?> |