set pdo attributes in constructor

This commit is contained in:
Miroslav Šedivý 2020-06-11 01:54:39 +02:00
parent f63bfe21bc
commit 0ba76adc1d

View file

@ -46,7 +46,12 @@ class DB
// Username
Config::get('mysql_user'),
// Password
Config::get_safe('mysql_pass', '')
Config::get_safe('mysql_pass', ''),
// Set attributes
[
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
\PDO::ATTR_EMULATE_PREPARES => false
]
);
$this->_PDO->exec(
@ -59,13 +64,6 @@ class DB
} catch (PDOException $e) {
throw new DBException($e->getMessage());
}
// When is this not set, chat does dot work, odd behavior
$this->_PDO->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
// Throwing exceptions
$this->_PDO->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
//$this->_PDO->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
}
// Just flattern array to be binded : [key1, key2, [key3, [key4]]] => [key1, key2, key3, key4]