public static function singleton()
 {
     if (!isset(self::$instance)) {
         $c = __CLASS__;
         self::$instance = new $c();
     }
     return self::$instance;
 }
示例#2
0
 /**
  * @param string|array|object $type
  * @param string $host
  * @param string $username
  * @param string $password
  * @param string $dbname
  * @param int $port
  * @param string $charset
  */
 public function __construct($type, $host = null, $username = null, $password = null, $dbname = null, $port = null, $charset = null)
 {
     if (is_array($type)) {
         // if params were passed as array
         $this->connectionParams = $type;
     } elseif (is_object($type)) {
         // if type is set as pdo object
         $this->pdo = $type;
     } else {
         foreach ($this->connectionParams as $key => $param) {
             if (isset(${$key}) && !is_null(${$key})) {
                 $this->connectionParams[$key] = ${$key};
             }
         }
     }
     if (isset($this->connectionParams['prefix'])) {
         $this->setPrefix($this->connectionParams['prefix']);
     }
     if (isset($this->connectionParams['isSubQuery'])) {
         $this->isSubQuery = true;
         return;
     }
     self::$instance = $this;
 }