dsn)) { $this->dsn = 'mysql:host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname); empty($this->port) OR $this->dsn .= ';port='.$this->port; empty($this->database) OR $this->dsn .= ';dbname='.$this->database; empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set; } elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 6) === FALSE && is_php('5.3.6')) { $this->dsn .= ';charset='.$this->char_set; } } // -------------------------------------------------------------------- /** * Non-persistent database connection * * @param bool * @return object */ public function db_connect($persistent = FALSE) { /* Prior to PHP 5.3.6, even if the charset was supplied in the DSN * on connect - it was ignored. This is a work-around for the issue. * * Reference: http://www.php.net/manual/en/ref.pdo-mysql.connection.php */ if ( ! is_php('5.3.6') && ! empty($this->char_set)) { $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES '.$this->char_set .(empty($this->dbcollat) ? '' : ' COLLATE '.$this->dbcollat); } return parent::db_connect($persistent); } // -------------------------------------------------------------------- /** * Show table query * * Generates a platform-specific query string so that the table names can be fetched * * @param bool * @return string */ protected function _list_tables($prefix_limit = FALSE) { $sql = 'SHOW TABLES'; if ($prefix_limit === TRUE && $this->dbprefix !== '') { return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'"; } return $sql; } // -------------------------------------------------------------------- /** * Show column query * * Generates a platform-specific query string so that the column names can be fetched * * @param string the table name * @return string */ protected function _list_columns($table = '') { return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE); } // -------------------------------------------------------------------- /** * Field data query * * Generates a platform-specific query so that the column data can be retrieved * * @param string the table name * @return string */ protected function _field_data($table) { return 'SELECT * FROM '.$this->protect_identifiers($table).' LIMIT 1'; } // -------------------------------------------------------------------- /** * Update_Batch statement * * Generates a platform-specific batch update string from the supplied data * * @param string the table name * @param array the update data * @param array the where clause * @return string */ protected function _update_batch($table, $values, $index, $where = NULL) { $ids = array(); foreach ($values as $key => $val) { $ids[] = $val[$index]; foreach (array_keys($val) as $field) { if ($field !== $index) { $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; } } } $cases = ''; foreach ($final as $k => $v) { $cases .= $k." = CASE \n" .implode("\n", $v)."\n" .'ELSE '.$k.' END), '; } return 'UPDATE '.$table.' SET '.substr($cases, 0, -2) .' WHERE '.(($where !== '' && count($where) > 0) ? implode(' ', $where).' AND ' : '') .$index.' IN('.implode(',', $ids).')'; } // -------------------------------------------------------------------- /** * Truncate statement * * Generates a platform-specific truncate string from the supplied data * * If the database does not support the truncate() command, * then this method maps to 'DELETE FROM table' * * @param string the table name * @return string */ protected function _truncate($table) { return 'TRUNCATE '.$table; } } /* End of file pdo_mysql_driver.php */ /* Location: ./system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php */