I am getting an error, and i am unsure what i have done wrong.
LIVE demo - http://www.designvisa.com/beta/include/dbconnect/opendb.php
$vconfig = new VConfig();
//Create objects from DBObject class.
$myObj = new DBConnect("localhost","$vconfig->user","$vconfig->dbpass","$vconfig->db");
//Call methods of objects.
$myObj ->connectToMySQL();
$myObj2 = new DBData();
$myObj2 ->selectDB();
$myObj2 ->showMessage();
class DBConnect{
/////////////////////////////////////////////////
// PRIVATE PROPERTIES
/////////////////////////////////////////////////
private $hostname, $username, $password, $db_name, $con;
/**
* Constructor
* @param String $hostname,$username,$password,$db_name.
* All information we need to provide whenever connect to db.
*/
public function __construct($hostname,$username,$password,$db_name){
$this->hostname = $hostname;
$this->username = $username;
$this->password = $password;
$this->db_name = $db_name;
}
/**
* Connect to MySQL.
* @return void
*/
public function connectToMySQL(){
$this->con = mysql_connect($this->hostname,$this->username,$this->password);
if($this->con){
echo "
Connected sucessfully to MySQL .
";
}
else{
die( "
Could not connect to MySQL" . mysql_error() . ".
");
}
}
}
class DBData extends DBConnect{
public function selectDB(){
$result = mysql_select_db($this->db_name,$this->con);
if($result){
echo "
Connected sucessfully to database ' ".$this->db_name." ' .
";
}
else{
die( "
Could not connect to database ' ". $this->db_name. " ' ".mysql_error() . ".
");
}
}
}
class DBClose extends DBConnect{
function closeConnection(){
//Do something else here and at the end you can
mysql_close();//For example
}
}
Can anyone help!