Example #1
1
 public static function getInstance()
 {
     if (!self::$_instance) {
         // If no instance then make one
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Example #2
0
 /**
  * 创建db对象
  */
 public static function getInstance()
 {
     if (!is_object(self::$_instance)) {
         self::$_instance = new Db();
     }
     return self::$_instance;
 }
 /**
  * @return Db
  */
 public static function instance()
 {
     if (is_null(self::$_instance)) {
         self::$_instance = self::factry();
     }
     return self::$_instance;
 }
Example #4
0
 /**
  * 取得数据库类实例
  * @static
  * @access public
  * @return mixed 返回数据库驱动类
  */
 public static function getInstance($db_config = '')
 {
     if (self::$_instance == null) {
         self::$_instance = new Db($db_config);
     }
     return self::$_instance;
 }
Example #5
0
 public static function getInstance()
 {
     if (self::$_instance == null) {
         self::$_instance = new PDO('mysql:host=localhost;dbname=localization;charset=utf8;"', 'root', 'sera');
     }
     return self::$_instance;
 }
Example #6
0
 public static function getInstance($which_db = 'model')
 {
     if (self::$_instance == null) {
         self::$_instance = self::_connect($which_db);
     }
     return self::$_instance;
 }
Example #7
0
 /**
  * Статическая функция, которая возвращает
  * экземпляр класса или создает новый при
  * необходимости
  * @return Db
  */
 public static function getInstance()
 {
     if (null === self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Example #8
0
 /**
  * 获取数据库单例实例
  *
  * @return object self
  * @author Seven Du <*****@*****.**>
  **/
 public static function getInstance($config = null)
 {
     if (!self::$_instance instanceof self) {
         self::$_instance = new self($config);
     }
     return self::$_instance;
 }
Example #9
0
 public static function getInstance()
 {
     if (!self::$_instance instanceof self) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Example #10
0
 /**
  * Get Db object instance (Singleton)
  *
  * @return object Db instance
  */
 public static function getInstance()
 {
     if (!isset(self::$_instance)) {
         self::$_instance = new MySQL();
     }
     return self::$_instance;
 }
Example #11
0
File: Db.php Project: autoDes/smth
 public static function getInstance()
 {
     if (is_null(self::$_instance)) {
         return self::$_instance = new self();
     } else {
         return self::$_instance;
     }
 }
Example #12
0
 public static function getInstance()
 {
     if (self::$_instance == null) {
         self::$_instance = new PDO("mysql:host=localhost;dbname=translations", "root", "");
         self::$_instance->query("SET NAMES utf8");
     }
     return self::$_instance;
 }
Example #13
0
File: Db.php Project: jortiz-el/PhP
 private function conectar()
 {
     $this->link = "mysql:host={$this->servidor};dbname={$this->base_datos}";
     try {
         self::$_instance = new PDO($this->link, $this->username, $this->passwd);
     } catch (PDOException $e) {
         echo "error: " . $e->getMessage();
     }
 }
Example #14
0
 public static function getInstance()
 {
     // If no instance then make one
     if (!self::$_instance) {
         //echo( "New connection<br>" );
         Logger::write("DEBUG", "New connection");
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Example #15
0
 public static function getInstance(array $config)
 {
     if (empty($config)) {
         throw new SixException("请传入正确的数据库参数!", 1);
     }
     $this->_config = array_filter($config);
     if (!self::$_instance instanceof self) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Example #16
0
 /**
  * 实例化
  */
 public static function getInstance()
 {
     // 判断是否被实例化
     // 访问实例的公共的静态方法
     if (!self::$_instance instanceof self) {
         //本类的属性$_instance是否是本类的实例
         //self指的是本类
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Example #17
0
File: Db.php Project: yiuked/tmcart
 /**
  * 获取一个数据库的单列
  *
  * @return object Db instance
  */
 public static function getInstance()
 {
     if (!self::$_instance) {
         if (DB_TYPE == 'pdo') {
             self::$_instance = new DbPdo(DB_SERVER, DB_USER, DB_PASSWD, DB_NAME);
         } elseif (DB_TYPE == 'mysqli') {
             self::$_instance = new DbMySQLI(DB_SERVER, DB_USER, DB_PASSWD, DB_NAME);
         } else {
             self::$_instance = new DbMySQL(DB_SERVER, DB_USER, DB_PASSWD, DB_NAME);
         }
     }
     return self::$_instance;
 }
Example #18
0
File: init.php Project: Kolyabis/my
 public static function getInstance()
 {
     if (self::$_instance instanceof PDO) {
         return self::$_instance;
     } else {
         try {
             return self::$_instance = new PDO(self::$dsn, self::$user, self::$password);
         } catch (Exception $error) {
             echo $error->getCode() . '<br>';
             echo $error->getMessage() . '<br>';
             echo $error->getLine() . '<br>';
         }
     }
 }
Example #19
0
 public static function getInstance()
 {
     if (self::$_instance === null) {
         $database = array();
         $database['type'] = 'mysql';
         $database['databases'] = 'lianjia';
         $database['server'] = 'localhost';
         $database['user'] = '******';
         $database['password'] = '******';
         $database['charset'] = 'utf8';
         $database['port'] = 3306;
         self::$_instance = new \Db\medoo(['database_type' => $database['type'], 'database_name' => $database['databases'], 'server' => $database['server'], 'username' => $database['user'], 'password' => $database['password'], 'charset' => $database['charset'], 'port' => $database['port'], 'option' => [PDO::ATTR_CASE => PDO::CASE_NATURAL]]);
     }
     return self::$_instance;
 }
Example #20
0
 /**
  * 取得数据库类实例
  * @static
  * @access public
  * @param mixed $config 连接配置
  * @return Object 返回数据库驱动类
  */
 public static function getInstance($config = array())
 {
     if (!$config) {
         $config = Yaf_Registry::get('database');
     }
     $id_server = count($config) == 1 ? 0 : 1;
     $md5 = md5(serialize($config));
     if (!isset(self::$instance[$md5])) {
         // 兼容mysqli
         if ('mysqli' == $config[$id_server]['type']) {
             $config[$id_server]['type'] = 'mysql';
         }
         // 如果采用lite方式 仅支持原生SQL 包括query和execute方法
         $class = ucwords(strtolower($config[$id_server]['type']));
         Yaf_Loader::import(dirname(__FILE__) . '/Db/Driver/' . $class . '.php');
         // if(file_exists($class.'.php')){
         self::$instance[$md5] = new $class($config[$id_server]);
         //}
     }
     self::$_instance = self::$instance[$md5];
     return self::$_instance;
 }
Example #21
0
 /**
  * 取得数据库类实例
  * @static
  * @access public
  * @param mixed $config 连接配置
  * @return Object 返回数据库驱动类
  */
 public static function getInstance($config = array())
 {
     $md5 = md5(serialize($config));
     if (!isset(self::$instance[$md5])) {
         // 解析连接参数 支持数组和字符串
         $options = self::parseConfig($config);
         // 兼容mysqli
         if ('mysqli' == $options['type']) {
             $options['type'] = 'mysql';
         }
         // 如果采用lite方式 仅支持原生SQL 包括query和execute方法
         $class = !empty($options['lite']) ? 'Think\\Db\\Lite' : 'Think\\Db\\Driver\\' . ucwords(strtolower($options['type']));
         if (class_exists($class)) {
             self::$instance[$md5] = new $class($options);
         } else {
             // 类没有定义
             E(L('_NO_DB_DRIVER_') . ': ' . $class);
         }
     }
     self::$_instance = self::$instance[$md5];
     return self::$_instance;
 }
Example #22
0
 public static function getInstance($config = array())
 {
     if (self::$_instance == null) {
         self::$_instance = new Db($config);
     }
     return self::$_instance;
 }
Example #23
0
 public static function set(Db $db)
 {
     self::$_instance = $db;
 }
Example #24
0
 /**
  * @param string $host
  * @param string $username
  * @param string $password
  * @param string $db
  * @param int $port
  */
 public function __construct($host = NULL, $username = NULL, $password = NULL, $db = NULL, $port = NULL, $charset = 'utf8')
 {
     $isSubQuery = false;
     // if params were passed as array
     if (is_array($host)) {
         foreach ($host as $key => $val) {
             ${$key} = $val;
         }
     }
     // if host were set as mysqli socket
     if (is_object($host)) {
         $this->_mysqli = $host;
     } else {
         $this->host = $host;
     }
     $this->username = $username;
     $this->password = $password;
     $this->db = $db;
     $this->port = $port;
     $this->charset = $charset;
     if ($isSubQuery) {
         $this->isSubQuery = true;
         return;
     }
     // for subqueries we do not need database connection and redefine root instance
     if (!is_object($host)) {
         $this->connect();
     }
     $this->setPrefix();
     self::$_instance = $this;
 }