diff --git a/library/think/db/Driver.php b/library/think/db/Driver.php index b52d1a29..b159ad2d 100644 --- a/library/think/db/Driver.php +++ b/library/think/db/Driver.php @@ -41,22 +41,23 @@ abstract class Driver protected $_linkID = null; // 数据库连接参数配置 protected $config = [ - 'type' => '', // 数据库类型 - 'hostname' => '127.0.0.1', // 服务器地址 - 'database' => '', // 数据库名 - 'username' => '', // 用户名 - 'password' => '', // 密码 - 'hostport' => '', // 端口 - 'dsn' => '', // - 'params' => [], // 数据库连接参数 - 'charset' => 'utf8', // 数据库编码默认采用utf8 - 'prefix' => '', // 数据库表前缀 - 'debug' => false, // 数据库调试模式 - 'deploy' => 0, // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) - 'rw_separate' => false, // 数据库读写是否分离 主从式有效 - 'master_num' => 1, // 读写分离后 主服务器数量 - 'slave_no' => '', // 指定从服务器序号 - 'db_like_fields' => '', //like字段自动替换为%%包裹 + 'type' => '', // 数据库类型 + 'hostname' => '127.0.0.1', // 服务器地址 + 'database' => '', // 数据库名 + 'username' => '', // 用户名 + 'password' => '', // 密码 + 'hostport' => '', // 端口 + 'dsn' => '', // + 'params' => [], // 数据库连接参数 + 'charset' => 'utf8', // 数据库编码默认采用utf8 + 'prefix' => '', // 数据库表前缀 + 'debug' => false, // 数据库调试模式 + 'deploy' => 0, // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) + 'rw_separate' => false, // 数据库读写是否分离 主从式有效 + 'master_num' => 1, // 读写分离后 主服务器数量 + 'slave_no' => '', // 指定从服务器序号 + 'db_like_fields' => '', // like字段自动替换为%%包裹 + 'debug' => false, // 是否调试 ]; // 数据库表达式 protected $exp = ['eq' => '=', 'neq' => '<>', 'gt' => '>', 'egt' => '>=', 'lt' => '<', 'elt' => '<=', 'notlike' => 'NOT LIKE', 'like' => 'LIKE', 'in' => 'IN', 'notin' => 'NOT IN', 'not in' => 'NOT IN', 'between' => 'BETWEEN', 'not between' => 'NOT BETWEEN', 'notbetween' => 'NOT BETWEEN']; diff --git a/library/think/db/driver/Mongo.php b/library/think/db/driver/Mongo.php index b343d66b..0335035d 100644 --- a/library/think/db/driver/Mongo.php +++ b/library/think/db/driver/Mongo.php @@ -48,7 +48,6 @@ class Mongo extends Driver $this->config['params'] = []; } } - $this->config = $config; } /** @@ -105,7 +104,7 @@ class Mongo extends Driver $this->_mongo = $this->_linkID->selectDb($db); } // 当前MongoCollection对象 - if (!empty($this->config['debug'])) { + if ($this->config['debug']) { $this->queryStr = $this->_dbName . '.getCollection(' . $collection . ')'; } if ($this->_collectionName != $collection) { @@ -217,7 +216,7 @@ class Mongo extends Driver } $this->model = $options['model']; $this->executeTimes++; - if (!empty($this->config['debug'])) { + if ($this->config['debug']) { $this->queryStr = $this->_dbName . '.' . $this->_collectionName . '.insert('; $this->queryStr .= $data ? json_encode($data) : '{}'; $this->queryStr .= ')'; @@ -277,7 +276,7 @@ class Mongo extends Driver */ public function getMongoNextId($pk) { - if (!empty($this->config['debug'])) { + if ($this->config['debug']) { $this->queryStr = $this->_dbName . '.' . $this->_collectionName . '.find({},{' . $pk . ':1}).sort({' . $pk . ':-1}).limit(1)'; } try { @@ -310,7 +309,7 @@ class Mongo extends Driver $this->model = $options['model']; $query = $this->parseWhere($options['where']); $set = $this->parseSet($data); - if (!empty($this->config['debug'])) { + if ($this->config['debug']) { $this->queryStr = $this->_dbName . '.' . $this->_collectionName . '.update('; $this->queryStr .= $query ? json_encode($query) : '{}'; $this->queryStr .= ',' . json_encode($set) . ')'; @@ -344,7 +343,7 @@ class Mongo extends Driver $query = $this->parseWhere($options['where']); $this->model = $options['model']; $this->executeTimes++; - if (!empty($this->config['debug'])) { + if ($this->config['debug']) { $this->queryStr = $this->_dbName . '.' . $this->_collectionName . '.remove(' . json_encode($query) . ')'; } try { @@ -370,7 +369,7 @@ class Mongo extends Driver } $this->model = $options['model']; $this->executeTimes++; - if (!empty($this->config['debug'])) { + if ($this->config['debug']) { $this->queryStr = $this->_dbName . '.' . $this->_collectionName . '.remove({})'; } try { @@ -405,10 +404,10 @@ class Mongo extends Driver } $this->model = $options['model']; $this->queryTimes++; - $query = $this->parseWhere(!empty($options['where']) ? $options['where'] : ''); + $query = $this->parseWhere(!empty($options['where']) ? $options['where'] : array()); $field = $this->parseField(!empty($options['field']) ? $options['field'] : ''); try { - if (!empty($this->config['debug'])) { + if ($this->config['debug']) { $this->queryStr = $this->_dbName . '.' . $this->_collectionName . '.find('; $this->queryStr .= $query ? json_encode($query) : '{}'; $this->queryStr .= $field ? ',' . json_encode($field) : ''; @@ -418,7 +417,7 @@ class Mongo extends Driver $_cursor = $this->_collection->find($query, $field); if ($options['order']) { $order = $this->parseOrder($options['order']); - if (!empty($this->config['debug'])) { + if ($this->config['debug']) { $this->queryStr .= '.sort(' . json_encode($order) . ')'; } $_cursor = $_cursor->sort($order); @@ -438,12 +437,12 @@ class Mongo extends Driver if (isset($options['limit'])) { list($offset, $length) = $this->parseLimit($options['limit']); if (!empty($offset)) { - if (!empty($this->config['debug'])) { + if ($this->config['debug']) { $this->queryStr .= '.skip(' . intval($offset) . ')'; } $_cursor = $_cursor->skip(intval($offset)); } - if (!empty($this->config['debug'])) { + if ($this->config['debug']) { $this->queryStr .= '.limit(' . intval($length) . ')'; } $_cursor = $_cursor->limit(intval($length)); @@ -485,7 +484,7 @@ class Mongo extends Driver $this->queryTimes++; $query = $this->parseWhere(!empty($options['where'])?$options['where']:''); $fields = $this->parseField(!empty($options['field'])?$options['field']:''); - if (!empty($this->config['debug'])) { + if ($this->config['debug']) { $this->queryStr = $this->_dbName . '.' . $this->_collectionName . '.findOne('; $this->queryStr .= $query ? json_encode($query) : '{}'; $this->queryStr .= $fields ? ',' . json_encode($fields) : ''; @@ -519,7 +518,7 @@ class Mongo extends Driver $this->model = $options['model']; $this->queryTimes++; $query = $this->parseWhere($options['where']); - if (!empty($this->config['debug'])) { + if ($this->config['debug']) { $this->queryStr = $this->_dbName . '.' . $this->_collectionName; $this->queryStr .= $query ? '.find(' . json_encode($query) . ')' : ''; $this->queryStr .= '.count()'; @@ -550,7 +549,7 @@ class Mongo extends Driver $this->switchCollection($collection, '', false); } $this->queryTimes++; - if (!empty($this->config['debug'])) { + if ($this->config['debug']) { $this->queryStr = $this->_dbName . '.' . $this->_collectionName . '.findOne()'; } try { @@ -581,7 +580,7 @@ class Mongo extends Driver */ public function getTables() { - if (!empty($this->config['debug'])) { + if ($this->config['debug']) { $this->queryStr = $this->_dbName . '.getCollenctionNames()'; } $this->queryTimes++;