From 2409448cec7884d4f7ff2a070a268c6235f42298 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Mon, 11 Jan 2016 11:45:02 +0900 Subject: [PATCH] Keep the charset stable, only setting it at install time --- classes/db/DBMysql.class.php | 30 +++++++------------------- classes/db/DBMysqli.class.php | 11 ++-------- modules/install/install.controller.php | 6 +++--- 3 files changed, 13 insertions(+), 34 deletions(-) diff --git a/classes/db/DBMysql.class.php b/classes/db/DBMysql.class.php index f2a1bc854..2fedd3528 100644 --- a/classes/db/DBMysql.class.php +++ b/classes/db/DBMysql.class.php @@ -19,7 +19,7 @@ class DBMysql extends DB */ var $prefix = 'xe_'; // / < var $comment_syntax = '/* %s */'; - var $charset = null; + var $charset = 'utf8'; /** * Column type used in MySQL @@ -84,15 +84,8 @@ class DBMysql extends DB } // Set charset - if(isset($connection["db_charset"])) - { - $charset = $this->charset = $connection["db_charset"]; - } - else - { - $charset = 'utf8'; - } - $this->_query("SET NAMES $charset", $connection); + $this->charset = isset($connection["db_charset"]) ? $connection["db_charset"] : 'utf8'; + $this->_query('SET NAMES ' . $this->charset, $connection); // select db @mysql_select_db($connection["db_database"], $result); @@ -581,10 +574,6 @@ class DBMysql extends DB $columns = $xml_obj->table->column; } - // Determine the character set and collation for this table - $charset = $this->getBestSupportedCharset(); - $collation = $charset . '_unicode_ci'; - // Initialize the list of indexes $primary_list = array(); $unique_list = array(); @@ -608,7 +597,7 @@ class DBMysql extends DB // This is 191 characters in utf8mb4 and 255 characters in utf8. if(($primary_key || $unique || $index) && preg_match('/(char|text)/i', $type)) { - if($size > 191 && $charset === 'utf8mb4') + if($size > 191 && $this->charset === 'utf8mb4') { $column_charset = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci'; } @@ -664,6 +653,8 @@ class DBMysql extends DB // Generate table schema $engine = stripos(get_class($this), 'innodb') === false ? 'MYISAM' : 'INNODB'; + $charset = $this->charset ?: 'utf8'; + $collation = $charset . '_unicode_ci'; $schema = sprintf("CREATE TABLE `%s` (%s) %s", $this->addQuotes($this->prefix . $table_name), "\n" . implode($column_schema, ",\n") . "\n", @@ -1006,11 +997,6 @@ class DBMysql extends DB */ function getBestSupportedCharset() { - if ($this->charset !== null) - { - return $this->charset; - } - if($output = $this->_fetch($this->_query("SHOW CHARACTER SET LIKE 'utf8%'"))) { $mb4_support = false; @@ -1021,11 +1007,11 @@ class DBMysql extends DB $mb4_support = true; } } - return $this->charset = ($mb4_support ? 'utf8mb4' : 'utf8'); + return $mb4_support ? 'utf8mb4' : 'utf8'; } else { - return $this->charset = 'utf8'; + return 'utf8'; } } } diff --git a/classes/db/DBMysqli.class.php b/classes/db/DBMysqli.class.php index 089288af4..95bfb4d3f 100644 --- a/classes/db/DBMysqli.class.php +++ b/classes/db/DBMysqli.class.php @@ -45,15 +45,8 @@ class DBMysqli extends DBMysql $this->setError($error, mysqli_connect_error()); return; } - if(isset($connection["db_charset"])) - { - $charset = $this->charset = $connection["db_charset"]; - } - else - { - $charset = 'utf8'; - } - mysqli_set_charset($result, $charset); + $this->charset = isset($connection["db_charset"]) ? $connection["db_charset"] : 'utf8'; + mysqli_set_charset($result, $this->charset); return $result; } diff --git a/modules/install/install.controller.php b/modules/install/install.controller.php index e339bb271..74e54205b 100644 --- a/modules/install/install.controller.php +++ b/modules/install/install.controller.php @@ -135,9 +135,9 @@ class installController extends install // Check DB charset if using MySQL if(stripos($db_info->master_db['db_type'], 'mysql') !== false && !isset($db_info->master_db['db_charset'])) { - $db_charset = $oDB->getBestSupportedCharset(); - $db_info->master_db['db_charset'] = $db_charset; - $db_info->slave_db[0]['db_charset'] = $db_charset; + $oDB->charset = $oDB->getBestSupportedCharset(); + $db_info->master_db['db_charset'] = $oDB->charset; + $db_info->slave_db[0]['db_charset'] = $oDB->charset; Context::setDBInfo($db_info); }