Hi,
I am currently using a db class to handle my database functions, but I want to connect to the DB every time an instance of that class is created. I am currently doing this:
And then using the class as follows:
What I would like to do is to connect automatically when the php creates an instance of the class. Is this possible please?
-Geeeeeeeeeeeeeeeeeeeeeeee-
I am currently using a db class to handle my database functions, but I want to connect to the DB every time an instance of that class is created. I am currently doing this:
Code:
class db { // class for handling db access
var $dbc = array('host' => 'localhost', 'user' => 'root', 'pass' => 'vivodigital007', 'db'=>'dmm');
// db config details
var $debug = 0;
// set debugging to OFF by default
function connect($name='dmm') { // connects to the database
// connects to the mysql database
$dbconn = mysql_connect($this->dbc['host'], $this->dbc['user'], $this->dbc['pass'])
or die('Could not connect: ' . mysql_error());
// connect to the msql db or die and display error
mysql_select_db($this->dbc['db']) or die('Could not select database: '.$name);
// select the mysql database or die and display error
}
And then using the class as follows:
Code:
require_once('db.inc.php');
$db = new db;
$db->connect();
What I would like to do is to connect automatically when the php creates an instance of the class. Is this possible please?
-Geeeeeeeeeeeeeeeeeeeeeeee-