Could you take a look at my simpleDB class and let me know what you think? what else should I add / remove?
class simpleDB { //Connection Variables private $db_host; private $db_port; private $db_user; private $db_pass; private $db_database; private $connection; private $query; private $connected = false; //Error Variables private $db_connection_error = "Sorry but something went wrong and I couldn't connect to the server, please try again later."; private $db_database_error = "Sorry but something went wrong and I couldn't connect to the database, please try again later."; //This is for older PHP 4 which dosnt support the __construct method function simpleDB () { $this->__construct(); } //When class is created - set up Database variables and try and connect public function __construct($host, $port, $user, $pass, $database) { //Set the Database Variables $this->db_host = $host; $this->db_user = $user; $this->db_pass = $pass; $this->db_database = $database; //See if custom port has been specified.. if (isset($port) && $port != ""){ $this->db_port = $port; } //If not set the port to 3306, the default MYSQL port else { $this->db_port = 3306; } //Connect to the Database $this->connect(); } //Connect to the Database private function connect() { $this->connection = mysql_connect($this->db_host.":".$this->db_port, $this->db_user, $this->db_pass) or die($this->db_connection_error); if($this->connection) { $database = mysql_select_db($this->db_database, $this->connection) or die($this->db_database_error); $this->connected = true; } } //Query the Database function query($query) { if (isset($this->connected) && $this->connected == true) { $this->query = $query; $this->query = mysql_query($this->query) or die(); } return $this->query; } //Return the Query as an Array - Some people may use it but I much prefer Objects/Accoc function fetch_array($array) { $this->array = $array; $this->array = mysql_fetch_array($this->array); $this->queries++; return $this->array; } //Count and return the number of rows returned from a query function num_rows($rows) { $this->rows = $rows; $this->rows = mysql_num_rows($this->rows); return $this->rows; } //Return the Query as an Associative Array function fetch_assoc($assoc) { $this->assoc = $assoc; $this->assoc = mysql_fetch_assoc($this->assoc); $this->queries++; return $this->assoc; } //Return the Query as an Object -> the methods become the field names function fetch_object($object) { $this->object = $object; $this->object = mysql_fetch_object($this->object); $this->queries++; return $this->object; } //Destroy the connection function destroy() { if (is_resource($this->query)) { mysql_free_result($this->query); } mysql_close($this->connection); } //end class }