/*
* Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
- * Copyright (C) 2002-2009 The Nucleus Group
+ * Copyright (C) 2002-2011 The Nucleus Group
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
*/
/**
* @license http://nucleuscms.org/license.txt GNU General Public License
- * @copyright Copyright (C) 2002-2009 The Nucleus Group
+ * @copyright Copyright (C) 2002-2011 The Nucleus Group
* @version $Id$
*/
if (function_exists('mysql_query') && !function_exists('sql_fetch_assoc'))
{
- /**
- *Errors before the database connection has been made
- */
- function startUpError($msg, $title) {
- ?>
-<html xmlns="http://www.w3.org/1999/xhtml">
- <head><title><?php echo htmlspecialchars($title)?></title></head>
- <body>
- <h1><?php echo htmlspecialchars($title)?></h1>
- <?php echo $msg?>
- </body>
+ /**
+ *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 <?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,ENT_QUOTES)?></h1>
+ <?php echo $msg?>
+ </body>
</html>
<?php
- exit;
- }
+ exit;
+ }
- /**
- * Connects to mysql server with arguments
- */
- function sql_connect_args($mysql_host = 'localhost', $mysql_user = '', $mysql_password = '', $mysql_database = '') {
-
- $CONN = @mysql_connect($mysql_host, $mysql_user, $mysql_password);
- if ($mysql_database) mysql_select_db($mysql_database,$CONN);
+ /**
+ * Connects to mysql server with arguments
+ */
+ function sql_connect_args($mysql_host = 'localhost', $mysql_user = '', $mysql_password = '', $mysql_database = '') {
+
+ $CONN = @mysql_connect($mysql_host, $mysql_user, $mysql_password);
+ if ($mysql_database) mysql_select_db($mysql_database,$CONN);
- return $CONN;
- }
-
- /**
- * Connects to mysql server
- */
- function sql_connect() {
- global $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE, $MYSQL_CONN;
+ return $CONN;
+ }
+
+ /**
+ * Connects to mysql server
+ */
+ function sql_connect() {
+ global $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE, $MYSQL_CONN;
- $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');
+ $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 ($mySqlVer >= '5.0.7' && phpversion() >= '5.2.3') {
- mysql_set_charset($charset);
- } elseif ($mySqlVer >= '4.1.0') {
- sql_query("SET CHARACTER SET " . $charset);
- }
+// <add for garble measure>
+ 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;
- }
+ return $MYSQL_CONN;
+ }
- /**
- * disconnects from SQL server
- */
- function sql_disconnect($conn = false) {
- global $MYSQL_CONN;
- if (!$conn) $conn = $MYSQL_CONN;
- @mysql_close($conn);
- }
-
- function sql_close($conn = false) {
- global $MYSQL_CONN;
- if (!$conn) $conn = $MYSQL_CONN;
- @mysql_close($conn);
- }
-
- /**
- * executes an SQL query
- */
- function sql_query($query, $conn = false) {
- global $SQLCount,$MYSQL_CONN;
- if (!$conn) $conn = $MYSQL_CONN;
- $SQLCount++;
- $res = mysql_query($query,$conn) or print("mySQL error with query $query: " . mysql_error($conn) . '<p />');
- return $res;
- }
-
- /**
- * executes an SQL error
- */
- function sql_error($conn = false)
- {
- global $MYSQL_CONN;
- if (!$conn) $conn = $MYSQL_CONN;
- return mysql_error($conn);
- }
-
- /**
- * executes an SQL db select
- */
- function sql_select_db($db,$conn = false)
- {
- global $MYSQL_CONN;
- if (!$conn) $conn = $MYSQL_CONN;
- return mysql_select_db($db,$conn);
- }
-
- /**
- * executes an SQL real escape
- */
- function sql_real_escape_string($val,$conn = false)
- {
- global $MYSQL_CONN;
- if (!$conn) $conn = $MYSQL_CONN;
- return mysql_real_escape_string($val,$conn);
- }
-
- /**
- * executes an PDO::quote() like escape, ie adds quotes arround the string and escapes chars as needed
- */
- function sql_quote_string($val,$conn = false) {
- global $MYSQL_CONN;
- if (!$conn) $conn = $MYSQL_CONN;
- return "'".mysql_real_escape_string($val,$conn)."'";
- }
-
- /**
- * executes an SQL insert id
- */
- function sql_insert_id($conn = false)
- {
- global $MYSQL_CONN;
- if (!$conn) $conn = $MYSQL_CONN;
- return mysql_insert_id($conn);
- }
-
- /**
- * executes an SQL result request
- */
- function sql_result($res, $row, $col)
- {
- return mysql_result($res,$row,$col);
- }
-
- /**
- * frees sql result resources
- */
- function sql_free_result($res)
- {
- return mysql_free_result($res);
- }
-
- /**
- * returns number of rows in SQL result
- */
- function sql_num_rows($res)
- {
- return mysql_num_rows($res);
- }
-
- /**
- * returns number of rows affected by SQL query
- */
- function sql_affected_rows($res)
- {
- return mysql_affected_rows($res);
- }
-
- /**
- * Get number of fields in result
- */
- function sql_num_fields($res)
- {
- return mysql_num_fields($res);
- }
-
- /**
- * fetches next row of SQL result as an associative array
- */
- function sql_fetch_assoc($res)
- {
- return mysql_fetch_assoc($res);
- }
-
- /**
- * Fetch a result row as an associative array, a numeric array, or both
- */
- function sql_fetch_array($res)
- {
- return mysql_fetch_array($res);
- }
-
- /**
- * fetches next row of SQL result as an object
- */
- function sql_fetch_object($res)
- {
- return mysql_fetch_object($res);
- }
-
- /**
- * Get a result row as an enumerated array
- */
- function sql_fetch_row($res)
- {
- return mysql_fetch_row($res);
- }
-
- /**
- * Get column information from a result and return as an object
- */
- function sql_fetch_field($res,$offset = 0)
- {
- return mysql_fetch_field($res,$offset);
- }
-
- /**
- * Get current system status (returns string)
- */
- function sql_stat($conn=false)
- {
- global $MYSQL_CONN;
- if (!$conn) $conn = $MYSQL_CONN;
- return mysql_stat($conn);
- }
-
- /**
- * Returns the name of the character set
- */
- function sql_client_encoding($conn=false)
- {
- global $MYSQL_CONN;
- if (!$conn) $conn = $MYSQL_CONN;
- return mysql_client_encoding($conn);
- }
-
- /**
- * Get SQL client version
- */
- function sql_get_client_info()
- {
- return mysql_get_client_info();
- }
-
- /**
- * Get SQL server version
- */
- function sql_get_server_info($conn=false)
- {
- global $MYSQL_CONN;
- if (!$conn) $conn = $MYSQL_CONN;
- return mysql_get_server_info($conn);
- }
-
- /**
- * Returns a string describing the type of SQL connection in use for the connection or FALSE on failure
- */
- function sql_get_host_info($conn=false)
- {
- global $MYSQL_CONN;
- if (!$conn) $conn = $MYSQL_CONN;
- return mysql_get_host_info($conn);
- }
-
- /**
- * Returns the SQL protocol on success, or FALSE on failure.
- */
- function sql_get_proto_info($conn=false)
- {
- global $MYSQL_CONN;
- if (!$conn) $conn = $MYSQL_CONN;
- return mysql_get_proto_info($conn);
- }
+ /**
+ * disconnects from SQL server
+ */
+ function sql_disconnect($conn = false) {
+ global $MYSQL_CONN;
+ if (!$conn) $conn = $MYSQL_CONN;
+ @mysql_close($conn);
+ }
+
+ function sql_close($conn = false) {
+ global $MYSQL_CONN;
+ if (!$conn) $conn = $MYSQL_CONN;
+ @mysql_close($conn);
+ }
+
+ /**
+ * executes an SQL query
+ */
+ function sql_query($query, $conn = false) {
+ global $SQLCount,$MYSQL_CONN;
+ if (!$conn) $conn = $MYSQL_CONN;
+ $SQLCount++;
+ $res = mysql_query($query,$conn) or print("mySQL error with query $query: " . mysql_error($conn) . '<p />');
+ return $res;
+ }
+
+ /**
+ * executes an SQL error
+ */
+ function sql_error($conn = false)
+ {
+ global $MYSQL_CONN;
+ if (!$conn) $conn = $MYSQL_CONN;
+ return mysql_error($conn);
+ }
+
+ /**
+ * executes an SQL db select
+ */
+ function sql_select_db($db,$conn = false)
+ {
+ global $MYSQL_CONN;
+ if (!$conn) $conn = $MYSQL_CONN;
+ return mysql_select_db($db,$conn);
+ }
+
+ /**
+ * executes an SQL real escape
+ */
+ function sql_real_escape_string($val,$conn = false)
+ {
+ global $MYSQL_CONN;
+ if (!$conn) $conn = $MYSQL_CONN;
+ return mysql_real_escape_string($val,$conn);
+ }
+
+ /**
+ * executes an PDO::quote() like escape, ie adds quotes arround the string and escapes chars as needed
+ */
+ function sql_quote_string($val,$conn = false) {
+ global $MYSQL_CONN;
+ if (!$conn) $conn = $MYSQL_CONN;
+ return "'".mysql_real_escape_string($val,$conn)."'";
+ }
+
+ /**
+ * executes an SQL insert id
+ */
+ function sql_insert_id($conn = false)
+ {
+ global $MYSQL_CONN;
+ if (!$conn) $conn = $MYSQL_CONN;
+ return mysql_insert_id($conn);
+ }
+
+ /**
+ * executes an SQL result request
+ */
+ function sql_result($res, $row, $col)
+ {
+ return mysql_result($res,$row,$col);
+ }
+
+ /**
+ * frees sql result resources
+ */
+ function sql_free_result($res)
+ {
+ return mysql_free_result($res);
+ }
+
+ /**
+ * returns number of rows in SQL result
+ */
+ function sql_num_rows($res)
+ {
+ return mysql_num_rows($res);
+ }
+
+ /**
+ * returns number of rows affected by SQL query
+ */
+ function sql_affected_rows($conn = false)
+ {
+ global $MYSQL_CONN;
+ if (!$conn) $conn = $MYSQL_CONN;
+ return mysql_affected_rows($conn);
+ }
+
+ /**
+ * Get number of fields in result
+ */
+ function sql_num_fields($res)
+ {
+ return mysql_num_fields($res);
+ }
+
+ /**
+ * fetches next row of SQL result as an associative array
+ */
+ function sql_fetch_assoc($res)
+ {
+ return mysql_fetch_assoc($res);
+ }
+
+ /**
+ * Fetch a result row as an associative array, a numeric array, or both
+ */
+ function sql_fetch_array($res)
+ {
+ return mysql_fetch_array($res);
+ }
+
+ /**
+ * fetches next row of SQL result as an object
+ */
+ function sql_fetch_object($res)
+ {
+ return mysql_fetch_object($res);
+ }
+
+ /**
+ * Get a result row as an enumerated array
+ */
+ function sql_fetch_row($res)
+ {
+ return mysql_fetch_row($res);
+ }
+
+ /**
+ * Get column information from a result and return as an object
+ */
+ function sql_fetch_field($res,$offset = 0)
+ {
+ return mysql_fetch_field($res,$offset);
+ }
+
+ /**
+ * Get current system status (returns string)
+ */
+ function sql_stat($conn=false)
+ {
+ global $MYSQL_CONN;
+ if (!$conn) $conn = $MYSQL_CONN;
+ return mysql_stat($conn);
+ }
+
+ /**
+ * Returns the name of the character set
+ */
+ function sql_client_encoding($conn=false)
+ {
+ global $MYSQL_CONN;
+ if (!$conn) $conn = $MYSQL_CONN;
+ return mysql_client_encoding($conn);
+ }
+
+ /**
+ * Get SQL client version
+ */
+ function sql_get_client_info()
+ {
+ return mysql_get_client_info();
+ }
+
+ /**
+ * Get SQL server version
+ */
+ function sql_get_server_info($conn=false)
+ {
+ global $MYSQL_CONN;
+ if (!$conn) $conn = $MYSQL_CONN;
+ return mysql_get_server_info($conn);
+ }
+
+ /**
+ * Returns a string describing the type of SQL connection in use for the connection or FALSE on failure
+ */
+ function sql_get_host_info($conn=false)
+ {
+ global $MYSQL_CONN;
+ if (!$conn) $conn = $MYSQL_CONN;
+ return mysql_get_host_info($conn);
+ }
+
+ /**
+ * Returns the SQL protocol on success, or FALSE on failure.
+ */
+ function sql_get_proto_info($conn=false)
+ {
+ global $MYSQL_CONN;
+ if (!$conn) $conn = $MYSQL_CONN;
+ return mysql_get_proto_info($conn);
+ }
- /**
- * Get the name of the specified field in a result
- */
- function sql_field_name($res, $offset = 0)
- {
- return mysql_field_name($res, $offset);
- }
+ /**
+ * Get the name of the specified field in a result
+ */
+ function sql_field_name($res, $offset = 0)
+ {
+ return mysql_field_name($res, $offset);
+ }
/**************************************************************************
- Unimplemented mysql_* functions
-
+ Unimplemented mysql_* functions
+
# mysql_ data_ seek (maybe useful)
# mysql_ errno (maybe useful)
# mysql_ fetch_ lengths (maybe useful)
# mysql_ field_ flags (maybe useful)
# mysql_ field_ len (maybe useful)
-# mysql_ field_ name (maybe useful)
# mysql_ field_ seek (maybe useful)
# mysql_ field_ table (maybe useful)
# mysql_ field_ type (maybe useful)
*******************************************************************/
-
-}
-?>
\ 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) {
+ 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 = sql_query("SET CHARACTER SET " . $charset);
+ }
+ return $res;
+ }
+}
\ No newline at end of file