// <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) {
# 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