File tree Expand file tree Collapse file tree 6 files changed +2865
-15
lines changed Expand file tree Collapse file tree 6 files changed +2865
-15
lines changed Original file line number Diff line number Diff line change 46
46
*/
47
47
class Db
48
48
{
49
- // 数据库配置
49
+ /**
50
+ * 数据库配置
51
+ * @var array
52
+ */
50
53
protected static $ config = [];
51
- // 数据库Query对象
54
+
55
+ /**
56
+ * 查询类名
57
+ * @var string
58
+ */
52
59
protected static $ query ;
53
- // 查询次数
60
+
61
+ /**
62
+ * 查询类自动映射
63
+ * @var array
64
+ */
65
+ protected static $ queryMap = [
66
+ 'mongo ' => '\\think \\db\Mongo ' ,
67
+ ];
68
+
69
+ /**
70
+ * 查询次数
71
+ * @var integer
72
+ */
54
73
public static $ queryTimes = 0 ;
55
- // 执行次数
74
+
75
+ /**
76
+ * 执行次数
77
+ * @var integer
78
+ */
56
79
public static $ executeTimes = 0 ;
57
- // 缓存对象Handler
80
+
81
+ /**
82
+ * 缓存对象
83
+ * @var object
84
+ */
58
85
protected static $ cacheHandler ;
59
86
60
87
public static function setConfig ($ config = [])
@@ -108,10 +135,16 @@ public static function getCacheHandler()
108
135
109
136
public static function __callStatic ($ method , $ args )
110
137
{
111
- $ class = self ::$ query ?: '\\think \\db \\Query ' ;
138
+ if (!self ::$ query ) {
139
+ $ type = strtolower (self ::getConfig ('type ' ));
140
+
141
+ $ class = isset (self ::$ queryMap [$ type ]) ? self ::$ queryMap [$ type ] : '\\think \\db \\Query ' ;
142
+
143
+ self ::$ query = $ class ;
144
+ }
112
145
113
- $ query = new $ class ( null , self ::$ config ) ;
146
+ $ class = self ::$ query ;
114
147
115
- return call_user_func_array ([$ query , $ method ], $ args );
148
+ return call_user_func_array ([new $ class , $ method ], $ args );
116
149
}
117
150
}
Original file line number Diff line number Diff line change 11
11
12
12
namespace think \db ;
13
13
14
+ use Exception ;
14
15
use InvalidArgumentException ;
15
16
use PDO ;
16
17
use PDOStatement ;
17
18
use think \Db ;
18
19
use think \db \exception \BindParamException ;
19
20
use think \db \exception \PDOException ;
20
- use think \Exception ;
21
21
22
22
abstract class Connection
23
23
{
@@ -227,6 +227,16 @@ public function getBuilder()
227
227
return $ this ->builder ;
228
228
}
229
229
230
+ /**
231
+ * 获取连接对象
232
+ * @access public
233
+ * @return object|null
234
+ */
235
+ public function getLinkID ()
236
+ {
237
+ return $ this ->linkID ?: null ;
238
+ }
239
+
230
240
/**
231
241
* 解析pdo连接的dsn信息
232
242
* @access protected
@@ -1949,9 +1959,7 @@ protected function multiConnect($master = false)
1949
1959
public function __destruct ()
1950
1960
{
1951
1961
// 释放查询
1952
- if ($ this ->PDOStatement ) {
1953
- $ this ->free ();
1954
- }
1962
+ $ this ->free ();
1955
1963
1956
1964
// 关闭连接
1957
1965
$ this ->close ();
You can’t perform that action at this time.
0 commit comments