| | |
| | | } |
| | | |
| | | /** |
| | | * Connect to appropiate database depending on the operation |
| | | * Connect to appropriate database depending on the operation |
| | | * |
| | | * @param string $mode Connection mode (r|w) |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Writes debug information/query to 'sql' log file |
| | | * |
| | | * @param string $query SQL query |
| | | */ |
| | | protected function debug($query) |
| | | { |
| | | if ($this->options['debug_mode']) { |
| | | rcube::write_log('sql', '[' . (++$this->db_index) . '] ' . $query . ';'); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Getter for error state |
| | | * |
| | | * @return boolean True on error |
| | | * @param int $res_id Optional query result identifier |
| | | * |
| | | * @return string Error message |
| | | */ |
| | | public function is_error() |
| | | public function is_error($res_id = null) |
| | | { |
| | | return $this->db_error ? $this->db_error_msg : false; |
| | | if ($res_id !== null) { |
| | | return $this->_get_result($res_id) === false ? $this->db_error_msg : null; |
| | | } |
| | | |
| | | return $this->db_error ? $this->db_error_msg : null; |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | $query = rtrim($query, ';'); |
| | | |
| | | if ($this->options['debug_mode']) { |
| | | rcube::write_log('sql', '[' . (++$this->db_index) . '] ' . $query . ';'); |
| | | } |
| | | $this->debug($query); |
| | | |
| | | $query = $this->dbh->query($query); |
| | | |
| | |
| | | return intval($input); |
| | | } |
| | | |
| | | if (is_null($input)) { |
| | | return 'NULL'; |
| | | } |
| | | |
| | | // create DB handle if not available |
| | | if (!$this->dbh) { |
| | | $this->db_connect('r'); |