public function getConnection()
{
if (!extension_loaded('pdo_mysql')) {
throw new RuntimeException('pdo_mysql extension is not installed');
}
$database = $this->getDatabaseName();
$connection = new PDO($this->getDsn(), $this->getUsername(), $this->getPassword());
/** @link http://bugs.mysql.com/bug.php?id=18551 */
$connection->query("SET SQL_MODE=''");
try {
$connection->query('USE ' . $this->quoteIdentifier($database));
} catch (PDOException $e) {
$message = sprintf("Unable to use database '%s': %s %s", $database, get_class($e), $e->getMessage());
throw new RuntimeException($message, 0, $e);
}
$connection->query("SET NAMES utf8");
$connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
$connection->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
return $connection;
}