| +--------------------------------------------------------------------------+ | Author: Aleksander Machniak | +--------------------------------------------------------------------------+ */ /** * Database independent query interface * * This is a wrapper for the PHP PDO */ class SQL_mysql extends SQL { public $db_provider = 'mysql'; /** * Object constructor */ public function __construct($conn_name, $conn_dsn) { parent::__construct($conn_name, $conn_dsn); // SQL identifiers quoting $this->options['identifier_start'] = '`'; $this->options['identifier_end'] = '`'; } /** * Driver-specific configuration of database connection */ protected function conn_configure() { if ($this->conn) { $this->conn->query("SET NAMES 'utf8'"); } } /** * Returns PDO DSN string from DSN array * * @param array $dsn DSN parameters * * @return string Connection string */ protected function dsn_string($dsn) { $params = array(); $result = 'mysql:'; if ($dsn['database']) { $params[] = 'dbname=' . $dsn['database']; } if ($dsn['hostspec']) { $params[] = 'host=' . $dsn['hostspec']; } if ($dsn['port']) { $params[] = 'port=' . $dsn['port']; } if ($dsn['socket']) { $params[] = 'unix_socket=' . $dsn['socket']; } $params[] = 'charset=utf8'; if (!empty($params)) { $result .= implode(';', $params); } return $result; } /** * Returns driver-specific connection options * * @param array $dsn DSN parameters * * @return array Connection options */ protected function dsn_options($dsn) { $result = array(); if (!empty($dsn['key'])) { $result[PDO::MYSQL_ATTR_SSL_KEY] = $dsn['key']; } if (!empty($dsn['cipher'])) { $result[PDO::MYSQL_ATTR_SSL_CIPHER] = $dsn['cipher']; } if (!empty($dsn['cert'])) { $result[PDO::MYSQL_ATTR_SSL_CERT] = $dsn['cert']; } if (!empty($dsn['capath'])) { $result[PDO::MYSQL_ATTR_SSL_CAPATH] = $dsn['capath']; } if (!empty($dsn['ca'])) { $result[PDO::MYSQL_ATTR_SSL_CA] = $dsn['ca']; } // Always return matching (not affected only) rows count $result[PDO::MYSQL_ATTR_FOUND_ROWS] = true; // Enable AUTOCOMMIT mode $result[PDO::ATTR_AUTOCOMMIT] = true; return $result; } }