link; } //----------------------------------------------------------------------- // Initialize db class // // function db($host=NULL, $username=NULL, $password=NULL, $db_name=NULL) { $this->connect($host,$username,$password); if($db_name!==NULL) { $this->select_db($db_name); } } //----------------------------------------------------------------------- //Connect to Database // // function connect($host='', $username='', $password='', $new_connection=TRUE) { $this->link=mysql_connect($host, $username, $password, $new_connection); if($this->link!=NULL) { return true; } return false; } //----------------------------------------------------------------------- //Close Database Connection // // function close() { if(mysql_close($this->link())) { return true; } else { return false; } } //----------------------------------------------------------------------- //Return the latest error // function error() { return mysql_error($this->link()); } //----------------------------------------------------------------------- // escape the passed in string // function escape_string($string) { return mysql_escape_string($string); } //----------------------------------------------------------------------- //Fetch the Array // function fetch_array($result) { return mysql_fetch_array($result); } //----------------------------------------------------------------------- //Fetch the Assoc // function fetch_assoc($result) { return mysql_fetch_assoc($result); } //----------------------------------------------------------------------- //Fetch the insert id // function insert_id() { return mysql_insert_id($this->link()); } function real_escape_string($string) { return mysql_escape_string($string); } function select_db($db_name='') { if(mysql_select_db($db_name, $this->link())) { return true; } else { return false; } } //----------------------------------------------------------------------- // fetch the number of rows // function num_rows($result) { $num_rows=mysql_num_rows($result); return $num_rows; } //----------------------------------------------------------------------- //Run a query // function query($query) { $result=mysql_query($query, $this->link()) or trigger_error('Error in Query: '.$query. ' - '.$this->error(), E_USER_ERROR); if($GLOBALS['config']->dev_mode) { echo 'Query: '.$query.'
'; } return $result; } } ?>