Use SET NAMES instead of charset for DB connection

When using charset in buildDsn, not all variables are set on the server side. That leads to MySQL assuming latin1 charset and errors with Cyrillic, for example (I figured out the letter 'И', capital breaks the things).
This commit is contained in:
kufeiko 2018-07-03 13:31:05 +03:00 committed by Frédéric Guillot
parent 8cee04101d
commit cfada3542e
1 changed files with 3 additions and 3 deletions

View File

@ -63,8 +63,7 @@ class Mysql extends Base
*/
protected function buildDsn(array $settings)
{
$charset = empty($settings['charset']) ? 'utf8' : $settings['charset'];
$dsn = 'mysql:host='.$settings['hostname'].';dbname='.$settings['database'].';charset='.$charset;
$dsn = 'mysql:host='.$settings['hostname'].';dbname='.$settings['database'];
if (! empty($settings['port'])) {
$dsn .= ';port='.$settings['port'];
@ -82,8 +81,9 @@ class Mysql extends Base
*/
protected function buildOptions(array $settings)
{
$charset = empty($settings['charset']) ? 'utf8' : $settings['charset'];
$options = array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET sql_mode = STRICT_ALL_TABLES',
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET sql_mode = STRICT_ALL_TABLES, NAMES ' . $charset,
);
if (! empty($settings['ssl_key'])) {