| | |
| | | 'dblib' => 'mssql', |
| | | 'mysqli' => 'mysql', |
| | | 'oci' => 'oracle', |
| | | 'oci8' => 'oracle', |
| | | ); |
| | | |
| | | $driver = isset($driver_map[$driver]) ? $driver_map[$driver] : $driver; |
| | |
| | | public function affected_rows($result = null) |
| | | { |
| | | if ($result || ($result === null && ($result = $this->last_result))) { |
| | | return $result->rowCount(); |
| | | if ($result !== true) { |
| | | return $result->rowCount(); |
| | | } |
| | | } |
| | | |
| | | return 0; |
| | |
| | | */ |
| | | public function num_rows($result = null) |
| | | { |
| | | if ($result || ($result === null && ($result = $this->last_result))) { |
| | | if (($result || ($result === null && ($result = $this->last_result))) && $result !== true) { |
| | | // repeat query with SELECT COUNT(*) ... |
| | | if (preg_match('/^SELECT\s+(?:ALL\s+|DISTINCT\s+)?(?:.*?)\s+FROM\s+(.*)$/ims', $result->queryString, $m)) { |
| | | $query = $this->dbh->query('SELECT COUNT(*) FROM ' . $m[1], PDO::FETCH_NUM); |
| | |
| | | protected function _fetch_row($result, $mode) |
| | | { |
| | | if ($result || ($result === null && ($result = $this->last_result))) { |
| | | return $result->fetch($mode); |
| | | if ($result !== true) { |
| | | return $result->fetch($mode); |
| | | } |
| | | } |
| | | |
| | | return false; |
| | |
| | | } |
| | | |
| | | return array(); |
| | | } |
| | | |
| | | /** |
| | | * Start transaction |
| | | * |
| | | * @return bool True on success, False on failure |
| | | */ |
| | | public function startTransaction() |
| | | { |
| | | $this->db_connect('w', true); |
| | | |
| | | // check connection before proceeding |
| | | if (!$this->is_connected()) { |
| | | return $this->last_result = false; |
| | | } |
| | | |
| | | $this->debug('BEGIN TRANSACTION'); |
| | | |
| | | return $this->last_result = $this->dbh->beginTransaction(); |
| | | } |
| | | |
| | | /** |
| | | * Commit transaction |
| | | * |
| | | * @return bool True on success, False on failure |
| | | */ |
| | | public function endTransaction() |
| | | { |
| | | $this->db_connect('w', true); |
| | | |
| | | // check connection before proceeding |
| | | if (!$this->is_connected()) { |
| | | return $this->last_result = false; |
| | | } |
| | | |
| | | $this->debug('COMMIT TRANSACTION'); |
| | | |
| | | return $this->last_result = $this->dbh->commit(); |
| | | } |
| | | |
| | | /** |
| | | * Rollback transaction |
| | | * |
| | | * @return bool True on success, False on failure |
| | | */ |
| | | public function rollbackTransaction() |
| | | { |
| | | $this->db_connect('w', true); |
| | | |
| | | // check connection before proceeding |
| | | if (!$this->is_connected()) { |
| | | return $this->last_result = false; |
| | | } |
| | | |
| | | $this->debug('ROLLBACK TRANSACTION'); |
| | | |
| | | return $this->last_result = $this->dbh->rollBack(); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public function table_name($table, $quoted = false) |
| | | { |
| | | // let plugins alter the table name (#1489837) |
| | | $plugin = rcube::get_instance()->plugins->exec_hook('db_table_name', array('table' => $table)); |
| | | $table = $plugin['table']; |
| | | |
| | | // add prefix to the table name if configured |
| | | if (($prefix = $this->options['table_prefix']) && strpos($table, $prefix) !== 0) { |
| | | $table = $prefix . $table; |