public function connect($type = "readwrite")
{
$conf = $this->config->getConnectionConfig($type);
$params = ['dbname' => $conf['database'], 'user' => $conf['user'], 'password' => $conf['password'], 'host' => $conf['host'], 'charset' => 'utf8', 'driver' => 'pdo_mysql'];
try {
$this->connections[$type] = DriverManager::getConnection($params);
$this->connections[$type]->setFetchMode(\PDO::FETCH_OBJ);
// https://github.com/Elgg/Elgg/issues/8121
$sub_query = "SELECT REPLACE(@@SESSION.sql_mode, 'ONLY_FULL_GROUP_BY', '')";
$this->connections[$type]->exec("SET SESSION sql_mode=({$sub_query});");
} catch (\PDOException $e) {
// @todo just allow PDO exceptions
// http://dev.mysql.com/doc/refman/5.1/en/error-messages-server.html
if ($e->getCode() == 1102 || $e->getCode() == 1049) {
$msg = "Elgg couldn't select the database '{$conf['database']}'. Please check that the database is created and you have access to it.";
} else {
$msg = "Elgg couldn't connect to the database using the given credentials. Check the settings file.";
}
throw new \DatabaseException($msg);
}
}