I have a database:
class dbConnect
{
var $strHost = "";
var $strDatabase = "";
var $strUser = "";
var $strPassword = "";
var $intLinkID = 0;
var $intQueryID = 0;
var $arrRecord = array();
var $intRow;
var $intErrno = 0;
var $strError = "";
function dbConnect()
{
$this->Connect();
}
function dbHalt($strError)
{
$objError = new errorHandle();
$objError->reportError("Database error: $strError", false);
$this->intErrno = mysql_errno($this->intLinkID);
$this->strError = mysql_error($this->intLinkID);
$strError = sprintf("MySQL Error: %s (%s)", $this->intErrno, $this->strError);
$objError->reportError($strError, true);
}
function Connect()
{
if (0 == $this->intLinkID)
{
$this->intLinkID=mysql_connect($this->strHost, $this->strUser, $this->strPassword);
if (!mysql_select_db($this->strDatabase, $this->intLinkID))
{
$this->dbHalt("cannot use database ". $this->strDatabase);
}
}
if (!$this->intLinkID)
{
$this->dbHalt("Database connection failed");
}
}
class dbMain extends dbConnect
{
// Database connection settings.
// Dev server.
var $strHost = 'db_host_here';
var $strUser = 'db_User_here';
var $strPassword = 'db_password_here';
var $strDatabase = 'db_name_here';
}
This works fine when calling $objDB = new dbMain();
But what I want is to dynamically set the database details in another class (for a master CMS) eg:
$objDB = new dbMain($user, $pass, $dbname, $dbhost);