Location: PHPKode > projects > Exero CMS > upload/class/mysql.php
<?
/*========================================*\
| Exero CMS                                |
|==========================================|
|          http://ecms.getox.net           |
|https://sourceforge.net/projects/exerocms/|
|==========================================|
|     Exero CMS is released under the      |
|     GNU General Public License (GPL)     |
| opensource.org/licenses/gpl-license.php  |
\*========================================*/
// Define a few things
define('IPADDRESS',$_SERVER['REMOTE_ADDR']);
// Start the class
class ecmsDatabase {
	var $link;
	var $mquery;
	var $appname = "";
	var $appver = "";
	var $query_count = 0;
	function connect($server,$user,$pass='') {
		$this->link = @mysql_connect($server,$user,$pass) or $this->dberror();
	}
	function selectdb($dbname) {
		mysql_select_db($dbname, $this->link) or $this->dberror();
	}
	function query($query) {
	global $query_count;
		$query = mysql_query($query, $this->link);
		if($this->errno()) {
			$this->dberror($query);
		}
		$query_count++;
		return $query;
	}
	function num_rows($query) {
		$rows = mysql_num_rows($query);
		return $rows;
	}
	function fetch_array($query,$type = MYSQL_ASSOC){
		$array = mysql_fetch_array($query, $type);
		return $array;
	}
	function query_first($query) {
		$getinfo = $this->query($query);
		$info = $this->fetch_array($getinfo);
		return $info;
	}
	function insert_id() {
		$instertid = mysql_insert_id();
		return $instertid;
	}
	function errno() {
		global $db;
		return mysql_errno();
	}
	function error() {
		return mysql_error();
	}
	function field_exists($field, $table)
	{
		global $db;
		$this->query("SELECT COUNT($field) AS count FROM $table", 1);
		if($this->errno())
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	function real_escape_string($string) {
		$escape = mysql_real_escape_string($string);
		return $escape;
	}
	function dberror($query='') {
		$message = "<html>\n";
		$message .= "<head>\n";
		$message .= "<title>".$this->appname." Database Error</title>\n";
		$message .= "</head>\n";
		$message .= "<style>\n";
		$message .= "body { font-family: arial; font-size: 12px; }";
		$message .= "</style>\n";
		$message .= "<body>\n";
		$message .= "<blockquote><blockquote><h2>".$this->appname." Database Error!</h2>\n";
		$message .= "Error: ".$this->error()."<br>\n";
		if(!isset($query)) {
			$message .= "Query: ".$query."<br>\n";
		}
		$message .= "MySQL Error No. ".$this->errno()."<br>\n";
		$message .= "IP Address: ".IPADDRESS."<br>\n";
		if($_SERVER['HTTP_REFERER'] != "") {
			$message .= "Referrer: ".$_SERVER['HTTP_REFERER']."<br>\n";
		}
		$message .= "File: ".$_SERVER['PHP_SELF']."<br>\n";
		if($_SERVER['QUERY_STRING'] != "") {
			$message .= "Query String: ".$_SERVER['QUERY_STRING']."<br>\n";
		}
		$message .= "Time: ".date("l jS F Y")." at ".date("g:i:sA T")."<br>\n";
		$message .= "</blockquote></blockquote>\n";
		$message .= "</body>\n";
		$message .= "</html>";
		echo $message;
		exit;
	}
}
?>
Return current item: Exero CMS