添加api接口的支持

This commit is contained in:
thinkphp
2015-05-12 15:34:04 +08:00
parent d886644b58
commit 36a84e75de
20 changed files with 247 additions and 196 deletions

View File

@@ -11,7 +11,7 @@
namespace think\db\driver;
use think\db\Driver;
use think\Exception;
/**
* Mongo数据库驱动
*/
@@ -31,7 +31,7 @@ class Mongo extends Driver {
*/
public function __construct($config=''){
if ( !class_exists('mongoClient') ) {
E(L('_NOT_SUPPERT_').':Mongo');
throw new Exception(L('_NOT_SUPPERT_').':Mongo');
}
if(!empty($config)) {
$this->config = array_merge($this->config,$config);
@@ -52,7 +52,7 @@ class Mongo extends Driver {
try{
$this->linkID[$linkNum] = new \mongoClient( $host,$this->config['params']);
}catch (\MongoConnectionException $e){
E($e->getmessage());
throw new Exception($e->getmessage());
}
}
return $this->linkID[$linkNum];
@@ -86,8 +86,8 @@ class Mongo extends Driver {
$this->debug(false);
$this->_collectionName = $collection; // 记录当前Collection名称
}
}catch (MongoException $e){
E($e->getMessage());
}catch (\MongoException $e){
throw new Exception($e->getMessage());
}
}
@@ -112,7 +112,7 @@ class Mongo extends Driver {
$result = $this->_mongo->command($command);
$this->debug(false);
if(!$result['ok']) {
E($result['errmsg']);
throw new Exception($result['errmsg']);
}
return $result;
}
@@ -133,7 +133,7 @@ class Mongo extends Driver {
if($result['ok']) {
return $result['retval'];
}else{
E($result['errmsg']);
throw new Exception($result['errmsg']);
}
}
@@ -194,7 +194,7 @@ class Mongo extends Driver {
}
return $result;
} catch (\MongoCursorException $e) {
E($e->getMessage());
throw new Exception($e->getMessage());
}
}
@@ -217,7 +217,7 @@ class Mongo extends Driver {
$this->debug(false);
return $result;
} catch (\MongoCursorException $e) {
E($e->getMessage());
throw new Exception($e->getMessage());
}
}
@@ -236,7 +236,7 @@ class Mongo extends Driver {
$result = $this->_collection->find([],[$pk=>1])->sort([$pk=>-1])->limit(1);
$this->debug(false);
} catch (\MongoCursorException $e) {
E($e->getMessage());
throw new Exception($e->getMessage());
}
$data = $result->getNext();
return isset($data[$pk])?$data[$pk]+1:1;
@@ -273,7 +273,7 @@ class Mongo extends Driver {
$this->debug(false);
return $result;
} catch (\MongoCursorException $e) {
E($e->getMessage());
throw new Exception($e->getMessage());
}
}
@@ -299,7 +299,7 @@ class Mongo extends Driver {
$this->debug(false);
return $result;
} catch (\MongoCursorException $e) {
E($e->getMessage());
throw new Exception($e->getMessage());
}
}
@@ -324,7 +324,7 @@ class Mongo extends Driver {
$this->debug(false);
return $result;
} catch (\MongoCursorException $e) {
E($e->getMessage());
throw new Exception($e->getMessage());
}
}
@@ -398,7 +398,7 @@ class Mongo extends Driver {
}
return $resultSet;
} catch (\MongoCursorException $e) {
E($e->getMessage());
throw new Exception($e->getMessage());
}
}
@@ -439,7 +439,7 @@ class Mongo extends Driver {
}
return $result;
} catch (\MongoCursorException $e) {
E($e->getMessage());
throw new Exception($e->getMessage());
}
}
@@ -467,7 +467,7 @@ class Mongo extends Driver {
$this->debug(false);
return $count;
} catch (\MongoCursorException $e) {
E($e->getMessage());
throw new Exception($e->getMessage());
}
}
@@ -493,7 +493,7 @@ class Mongo extends Driver {
$result = $this->_collection->findOne();
$this->debug(false);
} catch (\MongoCursorException $e) {
E($e->getMessage());
throw new Exception($e->getMessage());
}
if($result) { // 存在数据则分析字段
$info = [];
@@ -631,7 +631,7 @@ class Mongo extends Driver {
}else{
// 查询字段的安全过滤
if(!preg_match('/^[A-Z_\|\&\-.a-z0-9]+$/',trim($key))){
E(L('_ERROR_QUERY_').':'.$key);
throw new Exception(L('_ERROR_QUERY_').':'.$key);
}
$key = trim($key);
if(strpos($key,'|')) {