Código
class DBConnection { private $connection; // On instance created connect to db public function __construct() { $this->connect(); } private function connect() { require_once 'db_config.php'; $this->connection = @new mysqli(DB_HOST, DB_USER, DB_PASSWORD); if(!$this->connection) } private function disconnect() { $this->connection->close(); } public function __destruct() { // Check if connection was established if($this->connection != NULL) { $this->disconnect(); } } }