Implement more accurate management of the current charset

This commit is contained in:
Kijin Sung 2016-01-11 11:12:02 +09:00
parent ecac6d1490
commit d9a9cfe21b
4 changed files with 25 additions and 9 deletions

View file

@ -19,6 +19,7 @@ class DBMysql extends DB
*/ */
var $prefix = 'xe_'; // / < var $prefix = 'xe_'; // / <
var $comment_syntax = '/* %s */'; var $comment_syntax = '/* %s */';
var $charset = null;
/** /**
* Column type used in MySQL * Column type used in MySQL
@ -83,7 +84,14 @@ class DBMysql extends DB
} }
// Set charset // Set charset
$charset = isset($connection["db_charset"]) ? $connection["db_charset"] : 'utf8'; if(isset($connection["db_charset"]))
{
$charset = $this->charset = $connection["db_charset"];
}
else
{
$charset = 'utf8';
}
$this->_query("SET NAMES $charset", $connection); $this->_query("SET NAMES $charset", $connection);
// select db // select db
@ -998,13 +1006,12 @@ class DBMysql extends DB
*/ */
function getBestSupportedCharset() function getBestSupportedCharset()
{ {
static $cache = null; if ($this->charset !== null)
if ($cache !== null)
{ {
return $cache; return $this->charset;
} }
if($output = $this->_fetch($this->_query("SHOW CHARACTER SET LIKE 'utf8mb4%'"))) if($output = $this->_fetch($this->_query("SHOW CHARACTER SET LIKE 'utf8%'")))
{ {
$mb4_support = false; $mb4_support = false;
foreach($output as $row) foreach($output as $row)
@ -1014,11 +1021,11 @@ class DBMysql extends DB
$mb4_support = true; $mb4_support = true;
} }
} }
return $cache = ($mb4_support ? 'utf8' : 'utf8'); return $this->charset = ($mb4_support ? 'utf8mb4' : 'utf8');
} }
else else
{ {
return $cache = 'utf8'; return $this->charset = 'utf8';
} }
} }
} }

View file

@ -45,7 +45,14 @@ class DBMysqli extends DBMysql
$this->setError($error, mysqli_connect_error()); $this->setError($error, mysqli_connect_error());
return; return;
} }
$charset = isset($connection["db_charset"]) ? $connection["db_charset"] : 'utf8'; if(isset($connection["db_charset"]))
{
$charset = $this->charset = $connection["db_charset"];
}
else
{
$charset = 'utf8';
}
mysqli_set_charset($result, $charset); mysqli_set_charset($result, $charset);
return $result; return $result;
} }

View file

@ -133,7 +133,7 @@ class installController extends install
if(!$oDB->isConnected()) return $oDB->getError(); if(!$oDB->isConnected()) return $oDB->getError();
// Check DB charset if using MySQL // Check DB charset if using MySQL
if(stripos($db_info->master_db['db_type'], 'mysql') !== false) if(stripos($db_info->master_db['db_type'], 'mysql') !== false && !isset($db_info->master_db['db_charset']))
{ {
$db_charset = $oDB->getBestSupportedCharset(); $db_charset = $oDB->getBestSupportedCharset();
$db_info->master_db['db_charset'] = $db_charset; $db_info->master_db['db_charset'] = $db_charset;
@ -197,6 +197,7 @@ class installController extends install
'db_password' => Context::get('db_password'), 'db_password' => Context::get('db_password'),
'db_database' => Context::get('db_database'), 'db_database' => Context::get('db_database'),
'db_table_prefix' => Context::get('db_table_prefix'), 'db_table_prefix' => Context::get('db_table_prefix'),
'db_charset' => Context::get('db_charset'),
); );
$db_info->slave_db = array($db_info->master_db); $db_info->slave_db = array($db_info->master_db);
$db_info->default_url = Context::getRequestUri(); $db_info->default_url = Context::getRequestUri();

View file

@ -29,6 +29,7 @@ $install_config = array(
'db_password' => $dbinfo['password'], 'db_password' => $dbinfo['password'],
'db_database' => $dbinfo['dbname'], 'db_database' => $dbinfo['dbname'],
'db_table_prefix' =>'xe_', 'db_table_prefix' =>'xe_',
'db_charset' => 'utf8',
'use_rewrite' =>'N', 'use_rewrite' =>'N',
'time_zone' =>'0900', 'time_zone' =>'0900',
'email_address' =>'admin@admin.net', 'email_address' =>'admin@admin.net',