Reputation: 47
I have two php classes, the following:
class Database
class User
in class Database there is the __constructor to create Db connection:
$database = new Database();
$db = $database->dbConnect();
in class User i have included the class Database in this way:
require_once('database.php');
and the User constructor instantiate the db connection
//constructor
public function __construct() {
$database = new Database();
$db = $database->dbConnect();
$this->conn = $db;
}
How can I close the db connection correctly?
Upvotes: 0
Views: 148
Reputation: 11
You can either make destruct() method or you can make any custom method to close the db connection and call that method with that "$this->conn"
example :
mysqli_close($this->conn);
function __destruct(){
mysqli_close($this->conn);
}
First refer your database class file it might having connection close method.
Upvotes: 1