I have a database abstraction layer that starts with a base class like so:
class DB {
function DB() {
$this->host = "xxx";
$this->db = "xxx";
$this->user = "xx";
$this->pass = "xx";
$this->dbh = mysql_connect($this->host, $this->user, $this->pass);
mysql_select_db($this->db);
// etc
}
}
class DBI extends DB {
// etc
}
Now I would like for the child classes to inherit the database handle but not the credentials. I tried (in the DBI class):
function DBI (){
$this->host ='';
$this->db ='';
$this->user ='';
$this->pass ='';
}
But that kills the handle; not sure why. Also tried:
class DBI extends DB {
var $host ='';
var $db ='';
var $user ='';
var $pass ='';
}
to no effect.
So I am wondering if what I ought to do is just move the database connection out of the class altoghether? Just start the class file with a connection and leave it at that?
Opinions?