From cfada3542eb381093fc381a06d77e60268bad85d Mon Sep 17 00:00:00 2001 From: kufeiko Date: Tue, 3 Jul 2018 13:31:05 +0300 Subject: Use SET NAMES instead of charset for DB connection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- libs/picodb/lib/PicoDb/Driver/Mysql.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/picodb/lib/PicoDb/Driver/Mysql.php b/libs/picodb/lib/PicoDb/Driver/Mysql.php index 7e5cce0a..946fb7a3 100644 --- a/libs/picodb/lib/PicoDb/Driver/Mysql.php +++ b/libs/picodb/lib/PicoDb/Driver/Mysql.php @@ -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'])) { -- cgit v1.2.3