Could not connect to MySQL database.

', 'Connect Error'); $charset = _getDbCharset($MYSQL_DATABASE); if($charset) mysql_query("SET NAMES '$charset'"); mysql_select_db($MYSQL_DATABASE) or startUpError('

Could not select database: ' . mysql_error() . '

', '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. $result = mysql_query("SHOW CREATE DATABASE `$db`"); if (mysql_num_rows($result) < 0 ) { // The specified db name is wrong! return false; } $dbInfo = mysql_fetch_row($result); $pattern = '/40100 DEFAULT CHARACTER SET (\w+) /'; if ( (preg_match($pattern, $dbInfo[1], $match) > 0) ) { return $match[1]; } return false; } /** * 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) . '

'); 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); } /************************************************************************** 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) *******************************************************************/ } ?>