* Based on code written by Tyler Hall * Released under the Creative Commons license */ class Database { var $db = ''; var $result = ''; var $lastQuery = ''; var $lastError = ''; var $numQueries = 0; var $queries = array(); function Database($host, $user, $password, $dbname) { $this->db = mysql_connect($host, $user, $password) or die(mysql_error()); mysql_select_db($dbname, $this->db) or die(mysql_error()); } public function query($sql) { $this->lastQuery = $sql; $this->result = mysql_query($sql, $this->db); if (!$this->result) { $this->lastError = mysql_error() . "($sql)"; } $this->queries[] = $sql; $this->numQueries++; return $this->result; } public function getLastError() { return $this->lastError; } public function numQueries() { return $this->numQueries; } } /* Do a $GLOBALS['db'] = new Database('localhost', 'user', 'pass', 'database') or some such */ include_once "connect.inc.php"; ?>