summaryrefslogtreecommitdiff
path: root/includes/database/mysql/database.inc
diff options
context:
space:
mode:
Diffstat (limited to 'includes/database/mysql/database.inc')
-rw-r--r--includes/database/mysql/database.inc82
1 files changed, 82 insertions, 0 deletions
diff --git a/includes/database/mysql/database.inc b/includes/database/mysql/database.inc
new file mode 100644
index 000000000..feac5da1f
--- /dev/null
+++ b/includes/database/mysql/database.inc
@@ -0,0 +1,82 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Database interface code for MySQL database servers.
+ */
+
+/**
+ * @ingroup database
+ * @{
+ */
+
+class DatabaseConnection_mysql extends DatabaseConnection {
+
+ protected $transactionSupport;
+
+ public function __construct(Array $connection_options = array()) {
+
+ $connection_options += array(
+ 'transactions' => FALSE,
+ 'port' => 3306,
+ );
+ $this->transactionSupport = $connection_options['transactions'];
+
+ $dsn = 'mysql:host=' . $connection_options['host'] . ';port=' . $connection_options['port'] . ';dbname=' . $connection_options['database'];
+ parent::__construct($dsn, $connection_options['username'], $connection_options['password'], array(
+ // So we don't have to mess around with cursors and unbuffered queries by default.
+ PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => TRUE,
+ // Because MySQL's prepared statements skip the query cache, because it's dumb.
+ PDO::ATTR_EMULATE_PREPARES => TRUE,
+ ));
+ }
+
+ public function queryRange($query, Array $args, $from, $count, Array $options) {
+ // Backward compatibility hack, temporary.
+ $query = str_replace(array('%d' , '%f' , '%b' , "'%s'"), '?', $query);
+
+ return $this->query($query . ' LIMIT ' . $from . ', ' . $count, $args, $options);
+ }
+
+ public function queryTemporary($query, Array $args, $tablename) {
+ $query = preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE ' . $tablename . ' Engine=HEAP SELECT', $this->prefixTables($query));
+
+ return $this->query($query, $args, $options);
+ }
+
+ public function driver() {
+ return 'mysql';
+ }
+
+ public function databaseType() {
+ return 'mysql';
+ }
+
+ public function supportsTransactions() {
+ return $this->transactionSupport;
+ }
+
+ public function escapeTable($table) {
+ return preg_replace('/[^A-Za-z0-9_]+/', '', $table);
+ }
+
+ public function mapConditionOperator($operator) {
+ // We don't want to override any of the defaults.
+ return NULL;
+ }
+
+ /**
+ * @todo Remove this as soon as db_rewrite_sql() has been exterminated.
+ */
+ public function distinctField($table, $field, $query) {
+ $field_to_select = 'DISTINCT(' . $table . '.' . $field . ')';
+ // (?<!text) is a negative look-behind (no need to rewrite queries that already use DISTINCT).
+ return preg_replace('/(SELECT.*)(?:' . $table . '\.|\s)(?<!DISTINCT\()(?<!DISTINCT\(' . $table . '\.)' . $field . '(.*FROM )/AUsi', '\1 ' . $field_to_select . '\2', $query);
+ }
+}
+
+
+/**
+ * @} End of "ingroup database".
+ */