- <?php
- /*
- * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
- * Copyright (C) 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
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- * (see nucleus/documentation/index.html#license for more info)
- */
- /**
- * @license http://nucleuscms.org/license.txt GNU General Public License
- * @copyright Copyright (C) 2002-2009 The Nucleus Group
- * @version $Id$
- */
- /*
- * complete sql_* wrappers for mysql functions
- *
- * functions moved from globalfunctions.php: sql_connect, sql_disconnect, sql_query
- */
- $MYSQL_CONN = 0;
- {
- /**
- * Errors before the database connection has been made
- */
- function startUpError($msg, $title) {
- ?>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <body>
- <?php echo $msg?>
- </body>
- </html>
- <?php
- exit;
- }
- /**
- * Connects to mysql server with arguments
- */
- function sql_connect_args($mysql_host = 'localhost', $mysql_user = '', $mysql_password = '', $mysql_database = '') {
- if ($mysql_database) {
- $charset = _getDbCharset($mysql_database);
- }
- 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');
- $charset = _getDbCharset($MYSQL_DATABASE);
- mysql_select_db($MYSQL_DATABASE) or startUpError('<p>Could not select database: ' . mysql_error() . '</p>', 'Connect Error');
- return $MYSQL_CONN;
- }
- /**
- * Get DB default charset
- */
- function _getDbCharset($db) {
- if (!$db) {
- return false;
- }
- // We use a SHOW CREATE DATABASE command to show the original
- // SQL character set when DB was created.
- // The specified db name is wrong!
- return false;
- }
- $pattern = '/40100 DEFAULT CHARACTER SET (\w+) /';
- return $match[1];
- }
- return false;
- }
- /**
- * disconnects from SQL server
- */
- function sql_disconnect($conn = false) {
- global $MYSQL_CONN;
- if (!$conn) $conn = $MYSQL_CONN;
- }
- function sql_close($conn = false) {
- global $MYSQL_CONN;
- if (!$conn) $conn = $MYSQL_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;
- }
- /**
- * executes an SQL db select
- */
- function sql_select_db($db,$conn = false)
- {
- global $MYSQL_CONN;
- if (!$conn) $conn = $MYSQL_CONN;
- }
- /**
- * executes an SQL real escape
- */
- function sql_real_escape_string($val,$conn = false)
- {
- global $MYSQL_CONN;
- if (!$conn) $conn = $MYSQL_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;
- }
- /**
- * executes an SQL insert id
- */
- function sql_insert_id($conn = false)
- {
- global $MYSQL_CONN;
- if (!$conn) $conn = $MYSQL_CONN;
- }
- /**
- * executes an SQL result request
- */
- function sql_result($res, $row, $col)
- {
- }
- /**
- * frees sql result resources
- */
- function sql_free_result($res)
- {
- }
- /**
- * returns number of rows in SQL result
- */
- function sql_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;
- }
- /**
- * Get number of fields in result
- */
- function sql_num_fields($res)
- {
- }
- /**
- * fetches next row of SQL result as an associative array
- */
- function sql_fetch_assoc($res)
- {
- }
- /**
- * Fetch a result row as an associative array, a numeric array, or both
- */
- function sql_fetch_array($res)
- {
- }
- /**
- * fetches next row of SQL result as an object
- */
- function sql_fetch_object($res)
- {
- }
- /**
- * Get a result row as an enumerated array
- */
- function sql_fetch_row($res)
- {
- }
- /**
- * Get column information from a result and return as an object
- */
- function sql_fetch_field($res,$offset = 0)
- {
- }
- /**
- * Get current system status (returns string)
- */
- function sql_stat($conn=false)
- {
- global $MYSQL_CONN;
- if (!$conn) $conn = $MYSQL_CONN;
- }
- /**
- * Returns the name of the character set
- */
- function sql_client_encoding($conn=false)
- {
- global $MYSQL_CONN;
- if (!$conn) $conn = $MYSQL_CONN;
- }
- /**
- * Get SQL client version
- */
- function sql_get_client_info()
- {
- }
- /**
- * Get SQL server version
- */
- function sql_get_server_info($conn=false)
- {
- global $MYSQL_CONN;
- if (!$conn) $conn = $MYSQL_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;
- }
- /**
- * 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;
- }
- /**
- * Get the name of the specified field in a result
- */
- function sql_field_name($res, $offset = 0)
- {
- }
- /**************************************************************************
- 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_ seek (maybe useful)
- # mysql_ field_ table (maybe useful)
- # mysql_ field_ type (maybe useful)
- # mysql_ info (maybe useful)
- # mysql_ list_ processes (maybe useful)
- # mysql_ ping (maybe useful)
- # mysql_ set_ charset (maybe useful, requires php >=5.2.3 and mysql >=5.0.7)
- # mysql_ thread_ id (maybe useful)
- # mysql_ db_ name (useful only if working on multiple dbs which we do not do)
- # mysql_ list_ dbs (useful only if working on multiple dbs which we do not do)
- # mysql_ pconnect (probably not useful and could cause some unintended performance issues)
- # mysql_ unbuffered_ query (possibly useful, but complicated and not supported by all database drivers (pdo))
- # mysql_ change_ user (deprecated)
- # mysql_ create_ db (deprecated)
- # mysql_ db_ query (deprecated)
- # mysql_ drop_ db (deprecated)
- # mysql_ escape_ string (deprecated)
- # mysql_ list_ fields (deprecated)
- # mysql_ list_ tables (deprecated)
- # mysql_ tablename (deprecated)
- *******************************************************************/
- }
- ?>
Raw Paste