DB.php
1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?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);
}
}