OSDN Git Service

Add "sql_set_charset_jp" function and replace some codes, refering to http://japan...
authorsakamocchi <sakamocchi@1ca29b6e-896d-4ea0-84a5-967f57386b96>
Mon, 21 Mar 2011 03:52:02 +0000 (03:52 +0000)
committersakamocchi <sakamocchi@1ca29b6e-896d-4ea0-84a5-967f57386b96>
Mon, 21 Mar 2011 03:52:02 +0000 (03:52 +0000)
git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/nucleus-jp/trunk@1181 1ca29b6e-896d-4ea0-84a5-967f57386b96

utf8/install/index.php
utf8/nucleus/libs/globalfunctions.php
utf8/nucleus/libs/sql/mysql.php
utf8/nucleus/libs/sql/pdo.php

index 1847a80..ff2554a 100755 (executable)
@@ -625,13 +625,8 @@ function doInstall() {
 \r
 // <add for garble measure>\r
        // 2-2. set DEFAULT CHARSET and COLLATE\r
-       $mySqlVer = implode('.', array_map('intval', explode('.', sql_get_server_info($MYSQL_CONN))));\r
-//     if ($mySqlVer >= '5.0.7' && phpversion() >= '5.2.3') {//}\r
-       if (version_compare($mySqlVer, '5.0.7', '>=') && function_exists('mysql_set_charset')) {\r
-               mysql_set_charset($charset);\r
-       } elseif (version_compare($mySqlVer, '4.1.0', '>=')) {\r
-               sql_query("SET CHARACTER SET " . $charset);\r
-       }\r
+       $mySqlVer = implode('.', array_map('intval', explode('.', sql_get_server_info())));\r
+       sql_set_charset_jp($charset);\r
        $collation = ($charset == 'utf8') ? 'utf8_general_ci' : 'ujis_japanese_ci';\r
 // </add for garble measure>*/\r
 \r
@@ -721,7 +716,7 @@ function doInstall() {
                                        $query = str_replace($aTableNames, $aTableNamesPrefixed, $query);\r
                        }\r
 // <add for garble measure>\r
-                       if ($mysql_create != 1 && strpos($query, 'CREATE TABLE') === 0 && $mySqlVer >= '4.1.0') {\r
+                       if ($mysql_create != 1 && strpos($query, 'CREATE TABLE') === 0 && version_compare($mySqlVer, '4.1.0', '>=')) {\r
                                $query .= ' DEFAULT CHARACTER SET ' . $charset . ' COLLATE ' . $collation;\r
                        }\r
 // </add for garble measure>*/\r
index fb4d151..505623a 100755 (executable)
@@ -402,43 +402,7 @@ if (!encoding_check(false, false, _CHARSET)) {
        }\r
 }\r
 \r
-/*\r
- * for preventing I/O strings from auto-detecting the charactor encodings by MySQL\r
- * since 3.62_beta-jp\r
- * Jan.20, 2011 by kotorisan and cacher\r
- * refering to their conversation below,\r
- * http://japan.nucleuscms.org/bb/viewtopic.php?p=26581\r
- * \r
- * NOTE:       shift_jis is only supported for output. Using shift_jis in DB is prohibited.\r
- * NOTE:       iso-8859-x,windows-125x if _CHARSET is unset.\r
- */\r
-if (in_array('mysql',$MYSQL_HANDLER)) {\r
-       switch(strtolower(_CHARSET)){\r
-               case 'utf-8':\r
-                       $charset = 'utf8';\r
-                       break;\r
-               case 'euc-jp':\r
-                       $charset = 'ujis';\r
-                       break;\r
-               case 'gb2312':\r
-                       $charset = 'gb2312';\r
-                       break;\r
-               case 'shift_jis':\r
-                       $charset = 'sjis';\r
-                       break;\r
-               default:\r
-                       $resource = sql_query("show variables LIKE 'character_set_database'");\r
-                       $fetchDat = sql_fetch_assoc($resource);\r
-                       $charset  = $fetchDat['Value'];\r
-                       break;\r
-       }\r
-       $mySqlVer = implode('.', array_map('intval', explode('.', sql_get_server_info($MYSQL_CONN))));\r
-       if ($mySqlVer >= '5.0.7' && function_exists('mysql_set_charset')) {\r
-               mysql_set_charset($charset);\r
-       } elseif ($mySqlVer >= '4.1.0') {\r
-               sql_query("SET CHARACTER SET " . $charset);\r
-       }\r
-}\r
+sql_set_charset_jp(_CHARSET);\r
 \r
 /*\r
        Backed out for now: See http://forum.nucleuscms.org/viewtopic.php?t=3684 for details\r
index b1f81b2..69e3872 100755 (executable)
@@ -70,20 +70,21 @@ if (function_exists('mysql_query') && !function_exists('sql_fetch_assoc'))
 
                $MYSQL_CONN = @mysql_connect($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD) or startUpError('<p>Could not connect to MySQL database.</p>', 'Connect Error');
                mysql_select_db($MYSQL_DATABASE) or startUpError('<p>Could not select database: ' . mysql_error() . '</p>', 'Connect Error');
-               
-/*
+
 // <add for garble measure>
-               $resource = sql_query("show variables LIKE 'character_set_database'");
-               $fetchDat = sql_fetch_assoc($resource);
-               $charset  = $fetchDat['Value'];
-               $mySqlVer = implode('.', array_map('intval', explode('.', sql_get_server_info($MYSQL_CONN))));
-               if (version_compare($mySqlVer, '5.0.7', '>=') && function_exists('mysql_set_charset')) {
-                       mysql_set_charset($charset);
-               } elseif (version_compare($mySqlVer, '4.1.0', '>=')) {
-                       sql_query("SET CHARACTER SET " . $charset);
+               if (defined(_CHARSET)){
+                       $charset  = _CHARSET;
+               }else{
+                       $resource = sql_query("show variables LIKE 'character_set_database'");
+                       $fetchDat = sql_fetch_assoc($resource);
+                       $charset  = $fetchDat['Value'];
+                       // in trouble of encoding,uncomment the following line.
+                       // $charset = "ujis";
+                       // $charset = "utf8";
                }
-// </add for garble measure>
-*/
+               sql_set_charset_jp($charset);
+// </add for garble measure>*/
+
                return $MYSQL_CONN;
        }
 
@@ -343,4 +344,40 @@ if (function_exists('mysql_query') && !function_exists('sql_fetch_assoc'))
 # mysql_ tablename (deprecated)
 
 *******************************************************************/
+
+       /*
+        * for preventing I/O strings from auto-detecting the charactor encodings by MySQL
+        * since 3.62_beta-jp
+        * Jan.20, 2011 by kotorisan and cacher
+        * refering to their conversation below,
+        * http://japan.nucleuscms.org/bb/viewtopic.php?p=26581
+        * 
+        * 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) {
+               switch(strtolower($charset)){\r
+                       case 'utf-8':\r
+                               $charset = 'utf8';\r
+                               break;\r
+                       case 'euc-jp':\r
+                               $charset = 'ujis';\r
+                               break;\r
+                       case 'gb2312':\r
+                               $charset = 'gb2312';\r
+                               break;\r
+                       case 'shift_jis':\r
+                               $charset = 'sjis';\r
+                               break;\r
+                       default:\r
+                               break;\r
+               }
+               $mySqlVer = implode('.', array_map('intval', explode('.', sql_get_server_info())));
+               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 = sql_query("SET CHARACTER SET " . $charset);
+               }
+               return $res;
+       }
 }
\ No newline at end of file
index c2f3677..178f856 100755 (executable)
@@ -194,10 +194,17 @@ if (!function_exists('sql_fetch_assoc'))
                        
 // <add for garble measure>
                        if (strpos($MYSQL_HANDLER[1], 'mysql') === 0) {
-                               $resource = $SQL_DBH->query("show variables LIKE 'character_set_database'");
-                               $resource->bindColumn('Value', $charset);
-                               $resource->fetchAll();
-                               $SQL_DBH->exec("SET CHARACTER SET " . $charset);
+                               if (defined(_CHARSET)){
+                                       $charset  = _CHARSET;
+                               }else{
+                                       $resource = $SQL_DBH->query("show variables LIKE 'character_set_database'");
+                                       $resource->bindColumn('Value', $charset);
+                                       $resource->fetchAll();
+                                       // in trouble of encoding,uncomment the following line.
+                                       // $charset = "ujis";
+                                       // $charset = "utf8";
+                               }
+                               sql_set_charset_jp($charset);
                        }
 // </add for garble measure>*/
                } catch (PDOException $e) {
@@ -589,4 +596,41 @@ if (!function_exists('sql_fetch_assoc'))
 # mysql_ tablename (deprecated)
 
 *******************************************************************/
-}
\ No newline at end of file
+
+       /*
+        * for preventing I/O strings from auto-detecting the charactor encodings by MySQL
+        * since 3.62_beta-jp
+        * Jan.20, 2011 by kotorisan and cacher
+        * refering to their conversation below,
+        * http://japan.nucleuscms.org/bb/viewtopic.php?p=26581
+        * 
+        * 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) {
+               if (strpos($MYSQL_HANDLER[1], 'mysql') === 0) {
+                       switch(strtolower($charset)){\r
+                               case 'utf-8':\r
+                                       $charset = 'utf8';\r
+                                       break;\r
+                               case 'euc-jp':\r
+                                       $charset = 'ujis';\r
+                                       break;\r
+                               case 'gb2312':\r
+                                       $charset = 'gb2312';\r
+                                       break;\r
+                               case 'shift_jis':\r
+                                       $charset = 'sjis';\r
+                                       break;\r
+                               default:\r
+                                       break;\r
+                       }
+                       $mySqlVer = implode('.', array_map('intval', explode('.', sql_get_server_info())));
+                       if (version_compare($mySqlVer, '4.1.0', '>=')) {
+                               $res = $SQL_DBH->exec("SET CHARACTER SET " . $charset);
+                       }
+               }
+               return $res;
+       }
+}
+?>
\ No newline at end of file