From cdd8a3dc6f4199308b34a44015e330b666b4f6c9 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Thu, 6 Dec 2012 20:04:09 +0100 Subject: [PATCH] Small optimization --- .../system/database/MySQLDatabase.class.php | 36 ++----------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/wcfsetup/install/files/lib/system/database/MySQLDatabase.class.php b/wcfsetup/install/files/lib/system/database/MySQLDatabase.class.php index 963188a266..4fe119459d 100644 --- a/wcfsetup/install/files/lib/system/database/MySQLDatabase.class.php +++ b/wcfsetup/install/files/lib/system/database/MySQLDatabase.class.php @@ -24,46 +24,16 @@ class MySQLDatabase extends Database { if (!$this->port) $this->port = 3306; // mysql default port try { - $this->pdo = new \PDO('mysql:host='.$this->host.';port='.$this->port.';dbname='.$this->database, $this->user, $this->password); + $this->pdo = new \PDO('mysql:host='.$this->host.';port='.$this->port.';dbname='.$this->database, $this->user, $this->password, array( + \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8', SESSION sql_mode = 'ANSI,ONLY_FULL_GROUP_BY,STRICT_ALL_TABLES'" + )); $this->setAttributes(); } catch (\PDOException $e) { throw new DatabaseException("Connecting to MySQL server '".$this->host."' failed:\n".$e->getMessage(), $this); } - - // set sql mode - $this->setSQLMode(); - - // set connection character set - $this->setCharset(); } - /** - * Sets the MySQL sql_mode variable. - */ - protected function setSQLMode() { - try { - $statement = $this->prepareStatement("SET SESSION sql_mode = 'ANSI,ONLY_FULL_GROUP_BY,STRICT_ALL_TABLES'"); - $statement->execute(); - } - catch (DatabaseException $e) { - // ignore - } - } - - /** - * Sets the charset of the database connection. - */ - protected function setCharset() { - try { - $statement = $this->prepareStatement("SET NAMES 'utf8'"); - $statement->execute(); - } - catch (DatabaseException $e) { - // ignore - } - } - /** * @see wcf\system\database\Database::isSupported() */ -- 2.20.1