Skip to content

Commit

Permalink
内置mongodb支持
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Nov 23, 2017
1 parent 85a527e commit 6d80492
Show file tree
Hide file tree
Showing 6 changed files with 2,865 additions and 15 deletions.
49 changes: 41 additions & 8 deletions src/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,42 @@
*/
class Db
{
// 数据库配置
/**
* 数据库配置
* @var array
*/
protected static $config = [];
// 数据库Query对象

/**
* 查询类名
* @var string
*/
protected static $query;
// 查询次数

/**
* 查询类自动映射
* @var array
*/
protected static $queryMap = [
'mongo' => '\\think\\db\Mongo',
];

/**
* 查询次数
* @var integer
*/
public static $queryTimes = 0;
// 执行次数

/**
* 执行次数
* @var integer
*/
public static $executeTimes = 0;
// 缓存对象Handler

/**
* 缓存对象
* @var object
*/
protected static $cacheHandler;

public static function setConfig($config = [])
Expand Down Expand Up @@ -108,10 +135,16 @@ public static function getCacheHandler()

public static function __callStatic($method, $args)
{
$class = self::$query ?: '\\think\\db\\Query';
if (!self::$query) {
$type = strtolower(self::getConfig('type'));

$class = isset(self::$queryMap[$type]) ? self::$queryMap[$type] : '\\think\\db\\Query';

self::$query = $class;
}

$query = new $class(null, self::$config);
$class = self::$query;

return call_user_func_array([$query, $method], $args);
return call_user_func_array([new $class, $method], $args);
}
}
16 changes: 12 additions & 4 deletions src/db/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

namespace think\db;

use Exception;
use InvalidArgumentException;
use PDO;
use PDOStatement;
use think\Db;
use think\db\exception\BindParamException;
use think\db\exception\PDOException;
use think\Exception;

abstract class Connection
{
Expand Down Expand Up @@ -227,6 +227,16 @@ public function getBuilder()
return $this->builder;
}

/**
* 获取连接对象
* @access public
* @return object|null
*/
public function getLinkID()
{
return $this->linkID ?: null;
}

/**
* 解析pdo连接的dsn信息
* @access protected
Expand Down Expand Up @@ -1949,9 +1959,7 @@ protected function multiConnect($master = false)
public function __destruct()
{
// 释放查询
if ($this->PDOStatement) {
$this->free();
}
$this->free();

// 关闭连接
$this->close();
Expand Down

0 comments on commit 6d80492

Please sign in to comment.