Merge pull request #4016 from Icinga/fix/exceptions-with-mysql-8-3740

Set `COLLATE 'latin1_general_ci'` for `latin1` charsets on MySQL connections
This commit is contained in:
Johannes Meyer 2019-12-05 14:46:54 +01:00 committed by GitHub
commit f49ac81e42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -205,8 +205,15 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible, Insp
. 'ANSI_QUOTES,PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION\'';
if (isset($adapterParamaters['charset'])) {
$driverOptions[PDO::MYSQL_ATTR_INIT_COMMAND] .= ', NAMES ' . $adapterParamaters['charset'];
if (trim($adapterParamaters['charset']) === 'latin1') {
// Required for MySQL 8+ because we need PIPES_AS_CONCAT and
// have several columns with explicit COLLATE instructions
$driverOptions[PDO::MYSQL_ATTR_INIT_COMMAND] .= ' COLLATE latin1_general_ci';
}
unset($adapterParamaters['charset']);
}
$driverOptions[PDO::MYSQL_ATTR_INIT_COMMAND] .= ", time_zone='" . $this->defaultTimezoneOffset() . "'";
$driverOptions[PDO::MYSQL_ATTR_INIT_COMMAND] .=';';
$defaultPort = 3306;