diff options
author | webchick <webchick@24967.no-reply.drupal.org> | 2011-12-25 00:40:22 -0800 |
---|---|---|
committer | webchick <webchick@24967.no-reply.drupal.org> | 2011-12-25 00:40:22 -0800 |
commit | 2f6d917af5b7367e2956a16f76909ac09110b853 (patch) | |
tree | 8f42e2fd426e36e7912287bc025e30e67aa41581 /includes/database/mysql | |
parent | 15e66edf06ff2fa366e21c192fdfe5e35ca52f6e (diff) | |
download | brdo-2f6d917af5b7367e2956a16f76909ac09110b853.tar.gz brdo-2f6d917af5b7367e2956a16f76909ac09110b853.tar.bz2 |
Issue #1309278 by basic, Niklas Fiekas: Added Make PDO connection options configurable.
Diffstat (limited to 'includes/database/mysql')
-rw-r--r-- | includes/database/mysql/database.inc | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/includes/database/mysql/database.inc b/includes/database/mysql/database.inc index 7d5d85998..a57f7dd02 100644 --- a/includes/database/mysql/database.inc +++ b/includes/database/mysql/database.inc @@ -37,14 +37,20 @@ class DatabaseConnection_mysql extends DatabaseConnection { $dsn = 'mysql:host=' . $connection_options['host'] . ';port=' . (empty($connection_options['port']) ? 3306 : $connection_options['port']); } $dsn .= ';dbname=' . $connection_options['database']; - parent::__construct($dsn, $connection_options['username'], $connection_options['password'], array( + // Allow PDO options to be overridden. + $connection_options += array( + 'pdo' => array(), + ); + $connection_options['pdo'] += 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, // Force column names to lower case. PDO::ATTR_CASE => PDO::CASE_LOWER, - )); + ); + + parent::__construct($dsn, $connection_options['username'], $connection_options['password'], $connection_options['pdo']); // Force MySQL to use the UTF-8 character set. Also set the collation, if a // certain one has been set; otherwise, MySQL defaults to 'utf8_general_ci' @@ -56,14 +62,22 @@ class DatabaseConnection_mysql extends DatabaseConnection { $this->exec('SET NAMES utf8'); } - // Force MySQL's behavior to conform more closely to SQL standards. - // This allows Drupal to run almost seamlessly on many different - // kinds of database systems. These settings force MySQL to behave - // the same as postgresql, or sqlite in regards to syntax interpretation - // and invalid data handling. See http://drupal.org/node/344575 for - // further discussion. Also, as MySQL 5.5 changed the meaning of - // TRADITIONAL we need to spell out the modes one by one. - $this->exec("SET sql_mode='ANSI,STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER'"); + // Set MySQL init_commands if not already defined. Default Drupal's MySQL + // behavior to conform more closely to SQL standards. This allows Drupal + // to run almost seamlessly on many different kinds of database systems. + // These settings force MySQL to behave the same as postgresql, or sqlite + // in regards to syntax interpretation and invalid data handling. See + // http://drupal.org/node/344575 for further discussion. Also, as MySQL 5.5 + // changed the meaning of TRADITIONAL we need to spell out the modes one by + // one. + $connection_options += array( + 'init_commands' => array(), + ); + $connection_options['init_commands'] += array( + 'sql_mode' => "SET sql_mode = 'ANSI,STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER'", + ); + // Set connection options. + $this->exec(implode('; ', $connection_options['init_commands'])); } public function queryRange($query, $from, $count, array $args = array(), array $options = array()) { |