I am creating a database connection object, and I'm not sure what the best way would be...
If I create a dbConnection class which establishes the connection (using mysql_connect) can I then call mysql_query from anywhere in the main script?
what about from inside OTHER classes? Do i need to pass the object or attribute as parameters?
Basically, I'm looking for the best way (in terms of speed + memory) of connecting to the database ONCE using a simple class...
I've posted my constructor for the Database Connection class:
function __construct($database="") {
if (!empty($database)){ $this->db = $database; }
$this->dblink = mysql_connect($this->host,$this->username,$this->password);
if (!this->dblink) {
//Fatal Error
}
mysql_select_db($this->db, $this->dblink);
}