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 4646 */
4747class Db
4848{
49- // 数据库配置
49+ /**
50+ * 数据库配置
51+ * @var array
52+ */
5053 protected static $ config = [];
51- // 数据库Query对象
54+
55+ /**
56+ * 查询类名
57+ * @var string
58+ */
5259 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+ */
5473 public static $ queryTimes = 0 ;
55- // 执行次数
74+
75+ /**
76+ * 执行次数
77+ * @var integer
78+ */
5679 public static $ executeTimes = 0 ;
57- // 缓存对象Handler
80+
81+ /**
82+ * 缓存对象
83+ * @var object
84+ */
5885 protected static $ cacheHandler ;
5986
6087 public static function setConfig ($ config = [])
@@ -108,10 +135,16 @@ public static function getCacheHandler()
108135
109136 public static function __callStatic ($ method , $ args )
110137 {
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+ }
112145
113- $ query = new $ class ( null , self ::$ config ) ;
146+ $ class = self ::$ query ;
114147
115- return call_user_func_array ([$ query , $ method ], $ args );
148+ return call_user_func_array ([new $ class , $ method ], $ args );
116149 }
117150}
Original file line number Diff line number Diff line change 1111
1212namespace think \db ;
1313
14+ use Exception ;
1415use InvalidArgumentException ;
1516use PDO ;
1617use PDOStatement ;
1718use think \Db ;
1819use think \db \exception \BindParamException ;
1920use think \db \exception \PDOException ;
20- use think \Exception ;
2121
2222abstract class Connection
2323{
@@ -227,6 +227,16 @@ public function getBuilder()
227227 return $ this ->builder ;
228228 }
229229
230+ /**
231+ * 获取连接对象
232+ * @access public
233+ * @return object|null
234+ */
235+ public function getLinkID ()
236+ {
237+ return $ this ->linkID ?: null ;
238+ }
239+
230240 /**
231241 * 解析pdo连接的dsn信息
232242 * @access protected
@@ -1949,9 +1959,7 @@ protected function multiConnect($master = false)
19491959 public function __destruct ()
19501960 {
19511961 // 释放查询
1952- if ($ this ->PDOStatement ) {
1953- $ this ->free ();
1954- }
1962+ $ this ->free ();
19551963
19561964 // 关闭连接
19571965 $ this ->close ();
You can’t perform that action at this time.
0 commit comments