I am a beginner when it comes to working with OOP PHP and I would like to know how to properly close a database connection in OOP PHP. I have seen similar questions but none of the answers helped. Here is how I connect to the database:
<?php
class Db {
private $host = "localhost";
private $user = "root";
private $pwd = "";
private $dbName = "database";
protected function connect() {
$dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->dbName;
$pdo = new PDO($dsn, $this->user, $this->pwd);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
return $pdo;
}
}
So, how would I close this connection?