$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;
}
# 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,$mode = NULL) {
+ switch(strtolower($charset)){\r
+ case 'utf-8':
+ case 'utf8':\r
+ $charset = 'utf8';\r
+ break;\r
+ case 'euc-jp':
+ case 'ujis':\r
+ $charset = 'ujis';\r
+ break;\r
+ case 'gb2312':\r
+ $charset = 'gb2312';\r
+ break;
+ /*\r
+ case 'shift_jis':
+ case 'sjis':\r
+ $charset = 'sjis';\r
+ break;
+ */\r
+ default:
+ $charset = 'latin1';\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 = ($mode == 'NAMES')
+ ?sql_query("SET NAMES " . $charset)
+ :sql_query("SET CHARACTER SET " . $charset)
+ ;
+ }
+ return $res;
+ }
}
\ No newline at end of file