ZBlogPHP::InitializeDB PHP Method

InitializeDB() public static method

初始化数据库连接
public static InitializeDB ( string $type ) : object
$type string 数据连接类型
return object or null
    public static function InitializeDB($type)
    {
        if (!trim($type)) {
            return null;
        }
        $newtype = 'Db' . trim($type);
        return new $newtype();
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * 连接数据库
  * @return bool
  * @throws Exception
  */
 public function OpenConnect()
 {
     if ($this->isconnected) {
         return false;
     }
     if (!$this->option['ZC_DATABASE_TYPE']) {
         return false;
     }
     switch ($this->option['ZC_DATABASE_TYPE']) {
         case 'sqlite':
         case 'sqlite3':
         case 'pdo_sqlite':
             $this->db = ZBlogPHP::InitializeDB($this->option['ZC_DATABASE_TYPE']);
             if ($this->db->Open(array($this->usersdir . 'data/' . $this->option['ZC_SQLITE_NAME'], $this->option['ZC_SQLITE_PRE'])) == false) {
                 $this->ShowError(69, __FILE__, __LINE__);
             }
             break;
         case 'pgsql':
         case 'pdo_pgsql':
             $this->db = ZBlogPHP::InitializeDB($this->option['ZC_DATABASE_TYPE']);
             if ($this->db->Open(array($this->option['ZC_PGSQL_SERVER'], $this->option['ZC_PGSQL_USERNAME'], $this->option['ZC_PGSQL_PASSWORD'], $this->option['ZC_PGSQL_NAME'], $this->option['ZC_PGSQL_PRE'], $this->option['ZC_PGSQL_PORT'], $this->option['ZC_PGSQL_PERSISTENT'])) == false) {
                 $this->ShowError(67, __FILE__, __LINE__);
             }
             break;
         case 'mysql':
         case 'mysqli':
         case 'pdo_mysql':
         default:
             $this->db = ZBlogPHP::InitializeDB($this->option['ZC_DATABASE_TYPE']);
             if ($this->db->Open(array($this->option['ZC_MYSQL_SERVER'], $this->option['ZC_MYSQL_USERNAME'], $this->option['ZC_MYSQL_PASSWORD'], $this->option['ZC_MYSQL_NAME'], $this->option['ZC_MYSQL_PRE'], $this->option['ZC_MYSQL_PORT'], $this->option['ZC_MYSQL_PERSISTENT'], $this->option['ZC_MYSQL_ENGINE'])) == false) {
                 $this->ShowError(67, __FILE__, __LINE__);
             }
             break;
     }
     $this->isconnected = true;
     return true;
 }
All Usage Examples Of ZBlogPHP::InitializeDB
ZBlogPHP