mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-05 22:52:49 +08:00
添加api接口的支持
This commit is contained in:
@@ -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,'|')) {
|
||||
|
||||
@@ -59,19 +59,25 @@ class Oracle extends Driver{
|
||||
$this->debug(true);
|
||||
$this->PDOStatement = $this->_linkID->prepare($str);
|
||||
if(false === $this->PDOStatement) {
|
||||
E($this->error());
|
||||
}
|
||||
$result = $this->PDOStatement->execute($bind);
|
||||
$this->debug(false);
|
||||
if ( false === $result) {
|
||||
$this->error();
|
||||
return false;
|
||||
} else {
|
||||
$this->numRows = $this->PDOStatement->rowCount();
|
||||
if($flag || preg_match("/^\s*(INSERT\s+INTO|REPLACE\s+INTO)\s+/i", $str)) {
|
||||
$this->lastInsID = $this->_linkID->lastInsertId();
|
||||
}
|
||||
try{
|
||||
$result = $this->PDOStatement->execute($bind);
|
||||
$this->debug(false);
|
||||
if ( false === $result) {
|
||||
$this->error();
|
||||
return false;
|
||||
} else {
|
||||
$this->numRows = $this->PDOStatement->rowCount();
|
||||
if($flag || preg_match("/^\s*(INSERT\s+INTO|REPLACE\s+INTO)\s+/i", $str)) {
|
||||
$this->lastInsID = $this->_linkID->lastInsertId();
|
||||
}
|
||||
return $this->numRows;
|
||||
}
|
||||
return $this->numRows;
|
||||
}catch (\PDOException $e) {
|
||||
$this->error();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +135,7 @@ class Oracle extends Driver{
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function parseLimit($limit) {
|
||||
public function parseLimit($limit) {
|
||||
$limitStr = '';
|
||||
if(!empty($limit)) {
|
||||
$limit = explode(',',$limit);
|
||||
|
||||
Reference in New Issue
Block a user