A
A
alestro2015-12-06 17:33:17
PHP
alestro, 2015-12-06 17:33:17

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;
  }

The code is working, but is it possible to implement it somehow more pokasherno?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question