Answer the question
In order to leave comments, you need to log in
How to properly implement singleton in PDO?
There is a database class which returns only one pdo object.
All this is implemented as follows:
private static $instance;
private function __construct(){}
private function __clone(){}
public static function getInstance(){
$options = func_get_args();
$connectString=array_shift($options);
$user=array_shift($options);
$password=array_shift($options);
return !static::$instance instanceof PDO? static::$instance = new PDO($connectString,$user,$password,$options) : static::$instance;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question