diff options
author | kufeiko <kufeiko@gmail.com> | 2018-07-03 13:31:05 +0300 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2018-07-04 10:22:13 -0700 |
commit | cfada3542eb381093fc381a06d77e60268bad85d (patch) | |
tree | e1ddcb3651122cd661a7bdf82f56ad3cc6f75fbb /libs | |
parent | 8cee04101d351fb5321f225963d589883761d214 (diff) |
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).
Diffstat (limited to 'libs')
-rw-r--r-- | libs/picodb/lib/PicoDb/Driver/Mysql.php | 6 |
1 files 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'])) { |