this is my DataBase Class
class DataBase{
public $_localhost = "localhost";// server name => usually is localhost
public $_user = "root"; // username for the database
public $_password = "123"; // password for the database
public $_dbname = "ecommerce"; // database name
public $db = false;
public function __construct(){
try{
$this->db = new PDO("mysql:host=".$this->_localhost.";dbname=".$this->_dbname,$this->_user,$this->_password);
$this->db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$this->db->exec("SET NAMES utf8");
return $this->db;
}catch(PDOException $e){
echo $e->getMessage();
}
}
public function __destruct(){
$this->db = null;
}
}
Now in my Application Class
class Application{
public $db;
public function __construct(){
$this->db = new DataBase();
$this->db = $this->db->db;
}
}
As i want to use my destruct function to close my connection
Is that a good way to do this ?