From aec35ac6010393460c9c0065bec28e6deaa746ba Mon Sep 17 00:00:00 2001 From: sakamocchi Date: Wed, 30 Mar 2011 07:31:54 +0000 Subject: [PATCH] Fix the previous revision. The target database should be selected if we set character encoding in MySQL. Great help with yama.kyms, thanks! git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/nucleus-jp/trunk@1191 1ca29b6e-896d-4ea0-84a5-967f57386b96 --- utf8/install/index.php | 16 +++++++++------- utf8/nucleus/libs/sql/mysql.php | 7 ++----- utf8/nucleus/libs/sql/pdo.php | 7 ++----- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/utf8/install/index.php b/utf8/install/index.php index 0ee4aa1..bea211e 100755 --- a/utf8/install/index.php +++ b/utf8/install/index.php @@ -613,7 +613,7 @@ function doInstall() { showErrorMessages($errors); } - // 2-1. try to log in to mySQL + // 2. try to log in to mySQL global $MYSQL_CONN; // this will need to be changed if we ever allow @@ -623,14 +623,9 @@ function doInstall() { _doError(_ERROR15 . ': ' . sql_error() ); } -// - // 2-2. set DEFAULT CHARSET and COLLATE + // 3. try to create database (if needed) $mySqlVer = implode('.', array_map('intval', explode('.', sql_get_server_info()))); - sql_set_charset_jp($charset,'NAMES'); $collation = ($charset == 'utf8') ? 'utf8_general_ci' : 'ujis_japanese_ci'; -// */ - - // 3. try to create database (if needed) if ($mysql_create == 1) { $sql = 'CREATE DATABASE ' . $mysql_database; @@ -648,6 +643,13 @@ function doInstall() { // 4. try to select database sql_select_db($mysql_database,$MYSQL_CONN) or _doError(_ERROR17); + /* + * 4.5. set character set to this database in MySQL server + * This processing is added by Nucleus CMS Japanese Package Release Team as of Mar.30, 2011 + */ + sql_set_charset_jp($charset,'NAMES'); + + // 5. execute queries $filename = 'install.sql'; $fd = fopen($filename, 'r'); diff --git a/utf8/nucleus/libs/sql/mysql.php b/utf8/nucleus/libs/sql/mysql.php index 8ae98b7..10cc776 100755 --- a/utf8/nucleus/libs/sql/mysql.php +++ b/utf8/nucleus/libs/sql/mysql.php @@ -355,7 +355,7 @@ if (function_exists('mysql_query') && !function_exists('sql_fetch_assoc')) * NOTE: shift_jis is only supported for output. Using shift_jis in DB is prohibited. * NOTE: iso-8859-x,windows-125x if _CHARSET is unset. */ - function sql_set_charset_jp($charset,$mode = NULL) { + function sql_set_charset_jp($charset) { switch(strtolower($charset)){ case 'utf-8': case 'utf8': @@ -382,10 +382,7 @@ if (function_exists('mysql_query') && !function_exists('sql_fetch_assoc')) if (version_compare($mySqlVer, '5.0.7', '>=') && function_exists('mysql_set_charset')) { $res = mysql_set_charset($charset); } elseif (version_compare($mySqlVer, '4.1.0', '>=')) { - $res = ($mode == 'NAMES') - ?sql_query("SET NAMES " . $charset) - :sql_query("SET CHARACTER SET " . $charset) - ; + $res = sql_query("SET CHARACTER SET " . $charset); } return $res; } diff --git a/utf8/nucleus/libs/sql/pdo.php b/utf8/nucleus/libs/sql/pdo.php index 4f9f326..9f6f61b 100755 --- a/utf8/nucleus/libs/sql/pdo.php +++ b/utf8/nucleus/libs/sql/pdo.php @@ -607,7 +607,7 @@ if (!function_exists('sql_fetch_assoc')) * NOTE: shift_jis is only supported for output. Using shift_jis in DB is prohibited. * NOTE: iso-8859-x,windows-125x if _CHARSET is unset. */ - function sql_set_charset_jp($charset,$mode = NULL) { + function sql_set_charset_jp($charset) { global $MYSQL_HANDLER,$SQL_DBH; if (strpos($MYSQL_HANDLER[1], 'mysql') === 0) { switch(strtolower($charset)){ @@ -634,10 +634,7 @@ if (!function_exists('sql_fetch_assoc')) } $mySqlVer = implode('.', array_map('intval', explode('.', sql_get_server_info()))); if (version_compare($mySqlVer, '4.1.0', '>=')) { - $res = ($mode == 'NAMES') - ?$SQL_DBH->exec("SET NAMES " . $charset) - :$SQL_DBH->exec("SET CHARACTER SET " . $charset) - ; + $res = $SQL_DBH->exec("SET CHARACTER SET " . $charset); } } return $res; -- 2.11.0