DB.php 1.63 KB
<?php
/**
 * Created by PhpStorm.
 * User: Zip
 * Date: 14/12/9
 * Time: 下午10:32
 */

namespace Hood;

use Hood\Dao\Db\PDOMySQL;
use Hood\Dao\MongoDB\MongoCore;
use Hood\Dao\Db\PostgreSQL;

class DB
{
    /**
     * 原生不带缓存
     * @param $database
     * @return PDOMySQL\PDOConnection
     */
    static function Connection($database)
    {
        return new PDOMySQL\PDOConnection($database);
    }

    /**
     * 快速数据存取(带缓存的DB)
     * @param $database
     * @return PDOMySQL\Quick
     */
    static function Quick($database)
    {
        return new PDOMySQL\Quick($database);
    }

    /**
     * @param array $dbConfig
     *      array('dbname'=>'xxx','proxy'=>'xx');
     * @param array $options
     * @return PostgreSQL\PDOConnection
     * @throws PostgreSQL\DebugException
     * @throws \Exception
     */
    static function Postgre(array $dbConfig, array $options = array())
    {
        if (empty($dbConfig['dbname'])) {
            throw new \Exception('dbname is Null.');
        }
        $proxy = null;
        if (!empty($dbConfig['proxy'])) {
            $proxy = $dbConfig['proxy'];
        }
        $dsn = new PostgreSQL\Dsn();
        $dsnConfig = $dsn->getConfig($dbConfig['dbname'], $proxy);
        $config = array_merge($dsnConfig, $dbConfig);
        return new PostgreSQL\PDOConnection($config, $options);
    }

    /**
     * @return MongoCore
     */
    static function Mongo()
    {
        return new MongoCore();
    }


    /**
     * @param $database
     * @return PostgreSQL\Former
     */
    static function Former($database)
    {
        return new PostgreSQL\Former($database);
    }
}