*Errors before the database connection has been made
*/
function startUpError($msg, $title) {
+ if (!defined('_CHARSET')) {
+ define('_CHARSET', 'UTF-8');
+ }
+ if (!defined('_HTML_XML_NAME_SPACE_AND_LANG_CODE')) {
+ define('_HTML_XML_NAME_SPACE_AND_LANG_CODE', 'xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us"');
+ }
+ sendContentType('text/html','',_CHARSET);
?>
-<html xmlns="http://www.w3.org/1999/xhtml">
- <head><title><?php echo htmlspecialchars($title)?></title></head>
+<html <?php echo _HTML_XML_NAME_SPACE_AND_LANG_CODE; ?>>
+ <head><meta http-equiv="Content-Type" content="text/html; charset=<?php echo _CHARSET?>" />
+ <title><?php echo htmlspecialchars($title,ENT_QUOTES)?></title></head>
<body>
- <h1><?php echo htmlspecialchars($title)?></h1>
- <?php echo $msg?>
+ <h1><?php echo htmlspecialchars($title,ENT_QUOTES)?></h1>
+ <?php echo $msg?>
</body>
</html>
<?php
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 ($mySqlVer >= '5.0.7' && function_exists('mysql_set_charset')) {
- mysql_set_charset($charset);
- } elseif ($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";
}
+ sql_set_charset_jp($charset);
// </add for garble measure>*/
return $MYSQL_CONN;
*******************************************************************/
- /**
- * for JP installer only
- */
- function at_sql_query($query, $conn = false) {
- global $SQLCount,$MYSQL_CONN;
- if (!$conn) $conn = $MYSQL_CONN;
- $SQLCount++;
- $res = mysql_query($query,$conn);
+ /*
+ * 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
+}
\ No newline at end of file