I have done a little study on stackoverflow like this question [they talk on OOP perspective] and others. But, none adequately answer my question. I would also like to know the pros and cons of each. What I have now is a DB class as:
class DB extends DBWrapper{
private static $pdo = null;
public static function getInstance(){
if(self::$pdo == null){
self::PDOConnect();
}
return self::$pdo;
}
private static function PDOConnect(){
try{
self::$pdo = new \PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME, DB_USER, DB_PASS);
self::$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
self::$pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
} catch (\Exception $e){
die("Database Connection Failed");
}
}
}