* @version 1.0 * @package skyNomad */ /** * DB_Engine * @package skyNomad * @subpackage classes */ class db_engine { # --- Variables --- # Public /** * Contains the MySQL Host * @access public * @var string */ public $mysql_host; /** * Contains the MySQL Username * @access public * @var string */ public $mysql_user; /** * Contains the MySQL Password * @access public * @var string */ public $mysql_pass; /** * Contains the MySQL Database to acces * @access public * @var string */ public $mysql_db; # Private /** * Contains the Database Handler * @access private * @var mysql_connection */ private $link; /** * Contains the Logging Engine * @access private * @var global_log */ private $logger; /** * Contains the Database Connection Status * @access private * @var string */ private $status; /** * Sets whether or not to turn Debuggin on * @access private * @var string */ private $debug; # --- Functions --- /** * Constructor sets up {$mysql_host, $mysql_user, $mysql_pass, $mysql_db, $debug} */ function db_engine($mysql_host="", $mysql_user="", $mysql_pass="", $mysql_db="", $debug="0"){ # Initialise Variables $this->mysql_host = $mysql_host; $this->mysql_user = $mysql_user; $this->mysql_pass = $mysql_pass; $this->mysql_db = $mysql_db; $this->debug = $debug; $this->logger = 0; } /** * Connects to the MySQL database and sets up the database handler. */ function db_connect(){ # Create Connection To Database if ($this->mysql_host && $this->mysql_user && $this->mysql_pass){ $this->link = mysql_connect($this->mysql_host, $this->mysql_user, $this->mysql_pass); } else if ($this->mysql_host && $this->mysql_user && !($tyhis->mysql_pass)){ $this->link = mysql_connect($this->mysql_host, $this->mysql_user); } else if ($this->mysql_host && !($this->mysql_user) && !($tyhis->mysql_pass)){ $this->link = mysql_connect($this->mysql_host); } # Handle any errors $this->err_handler(mysql_error()); # Set Database if ($this->mysql_db){ mysql_select_db($this->mysql_db, $this->link); } # Handle any errors $this->err_handler(mysql_error()); } /** * Connects to the database, executes a query, returns the result * if needed, and closes the connection. * @param string $query The SQL query to execute. * @return mysql_result */ function query($query){ # Connect To Database $this->db_connect(); # Execute SQL Command $result = mysql_query($query); # Handle Errors $this->err_handler(mysql_error()); # Return Result return $result; } /** * Handles any errors that are generated by MySQL. If $debug is set * to true, then the error will be displayed. * @param mysql_error $err The MySQL Error object. */ function err_handler($err){ if ($err) { if ($this->debug){ # Output error print "