Apply charset and collation only if they are specified
This commit is contained in:
@ -32,8 +32,16 @@ class Database {
|
||||
$driver_options = array(
|
||||
'TIME_ZONE = "' . Env::$db_timezone_offset . '"',
|
||||
'sql_mode=(SELECT REPLACE(@@sql_mode,"ONLY_FULL_GROUP_BY",""))',
|
||||
'NAMES ' . Env::$db_charset . ' COLLATE ' . ENV::$db_collation,
|
||||
);
|
||||
|
||||
if(!empty(Env::$db_charset)) {
|
||||
$character_set = 'NAMES ' . Env::$db_charset;
|
||||
if(!empty(Env::$db_collation)) {
|
||||
$character_set .= ' COLLATE ' . Env::$db_collation;
|
||||
}
|
||||
$driver_options[] = $character_set;
|
||||
}
|
||||
|
||||
$current_options = ORM::for_table("")
|
||||
->raw_query('SELECT @@session.wait_timeout as wait_timeout')
|
||||
->findOne();
|
||||
|
@ -67,11 +67,11 @@ class Env {
|
||||
self::$db_charset = $wpdb->charset;
|
||||
self::$db_collation = $wpdb->collate;
|
||||
self::$db_charset_collate = $wpdb->get_charset_collate();
|
||||
self::$db_source_name = self::dbSourceName(self::$db_host, self::$db_socket, self::$db_port);
|
||||
self::$db_source_name = self::dbSourceName(self::$db_host, self::$db_socket, self::$db_port, self::$db_charset);
|
||||
self::$db_timezone_offset = self::getDbTimezoneOffset();
|
||||
}
|
||||
|
||||
private static function dbSourceName($host, $socket, $port) {
|
||||
private static function dbSourceName($host, $socket, $port, $charset) {
|
||||
$source_name = array(
|
||||
(!$socket) ? 'mysql:host=' : 'mysql:unix_socket=',
|
||||
$host,
|
||||
@ -82,6 +82,9 @@ class Env {
|
||||
'dbname=',
|
||||
DB_NAME
|
||||
);
|
||||
if(!empty($charset)) {
|
||||
$source_name[] = ';charset=' . $charset;
|
||||
}
|
||||
return implode('', $source_name);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user