|
@@ -6,6 +6,7 @@ use Aliyun\OTS\Consts\OperationTypeConst;
|
|
|
use Aliyun\OTS\Consts\PrimaryKeyTypeConst;
|
|
|
use Aliyun\OTS\Consts\RowExistenceExpectationConst;
|
|
|
use Aliyun\OTS\OTSClient;
|
|
|
+use PDO;
|
|
|
/**
|
|
|
* 查询Gps股轨迹 表格存储
|
|
|
*/
|
|
@@ -1254,11 +1255,12 @@ use Aliyun\OTS\OTSClient;
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 查询oracle数据库
|
|
|
+ * 查询oracle数据库 select
|
|
|
* @time 2021年05月18日 10:15
|
|
|
* @param Request $request
|
|
|
*/
|
|
|
function queryOracleSelect($tableName,$cond){
|
|
|
+ $conn = null;
|
|
|
if(!isset($cond['page'])){
|
|
|
$cond['page']=1;
|
|
|
}
|
|
@@ -1273,43 +1275,101 @@ use Aliyun\OTS\OTSClient;
|
|
|
|
|
|
$conn = new PDO("oci:dbname=//".$host.":".$port."/".$instance_name,$username,$password);// PDO方式
|
|
|
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
- // $conn->query("set names utf8");
|
|
|
+
|
|
|
$start=($cond['page']-1)*$cond['limit'];
|
|
|
$end=$cond['page']*$cond['limit'];
|
|
|
- $countQuery='SELECT count(*) as count FROM '.$tableName;
|
|
|
- $countRes= $conn -> query($countQuery)->fetch(PDO::FETCH_ASSOC);
|
|
|
-
|
|
|
- $sql = 'SELECT * FROM (SELECT a.*, ROWNUM rn FROM '.$tableName.' a) WHERE rn >= '. $start.' AND rn <= '.$end;
|
|
|
|
|
|
+ $whereStr=buildQueryCond($cond);
|
|
|
+
|
|
|
+ $sql = 'SELECT * FROM ( SELECT a.*, ROWNUM RN FROM (SELECT * FROM '.$tableName.' '.$whereStr.' ORDER BY ID DESC) a WHERE ROWNUM <='.$end.' ) WHERE RN >='. $start;
|
|
|
$res = $conn -> query($sql);
|
|
|
- // var_dump($res);
|
|
|
$rows = $res -> fetchAll(PDO::FETCH_ASSOC);
|
|
|
- $res=[
|
|
|
- 'count'=>(int)$countRes['COUNT'],
|
|
|
- 'data'=>$rows,
|
|
|
- 'current'=>$cond['page'],
|
|
|
- 'limit'=>$cond['limit'],
|
|
|
- ];
|
|
|
if ($conn){
|
|
|
$conn = null;
|
|
|
}
|
|
|
- return $res;
|
|
|
+ // $rows=[];
|
|
|
+ return $rows;
|
|
|
}
|
|
|
- function ascii_decode($sacii)
|
|
|
-
|
|
|
- {
|
|
|
-
|
|
|
- $asc = str_split(strtolower($sacii), 2);
|
|
|
- // var_dump($asc);
|
|
|
- $str ='';
|
|
|
-
|
|
|
- for ($i = 0; $i < count($asc); $i++) {
|
|
|
+ /**
|
|
|
+ * 查询oracle数据库 count
|
|
|
+ * @time 2021年05月18日 10:15
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ function queryOracleFind($tableName,$cond){
|
|
|
+ $conn = null;
|
|
|
+ if(!$cond){
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ $host= Env::get('oracle.hostname', '127.0.0.1');
|
|
|
+ $port= Env::get('oracle.hostport', '1521');
|
|
|
+ $instance_name= Env::get('oracle.instance', 'ORCL');
|
|
|
+ $username= Env::get('oracle.username', 'root');
|
|
|
+ $password= Env::get('oracle.password', 'root');
|
|
|
+
|
|
|
+ $conn = new PDO("oci:dbname=//".$host.":".$port."/".$instance_name,$username,$password);// PDO方式
|
|
|
+ $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
+
|
|
|
|
|
|
- $str.= chr(hexdec($asc[$i][0].$asc[$i][1]));
|
|
|
+ $sql='SELECT * FROM '.$tableName.' WHERE ';
|
|
|
+ foreach($cond as $key=>$val){
|
|
|
+ $sql .=$key.' '.$val[0].' '.$val[1];
|
|
|
+ }
|
|
|
+
|
|
|
+ $res= $conn -> query($sql)->fetch(PDO::FETCH_ASSOC);
|
|
|
+ if ($conn){
|
|
|
+ $conn = null;
|
|
|
+ }
|
|
|
+ // $response=[];
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 查询oracle数据库 count
|
|
|
+ * @time 2021年05月18日 10:15
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ function queryOracleCount($tableName,$cond){
|
|
|
+ $conn = null;
|
|
|
+ $host= Env::get('oracle.hostname', '127.0.0.1');
|
|
|
+ $port= Env::get('oracle.hostport', '1521');
|
|
|
+ $instance_name= Env::get('oracle.instance', 'ORCL');
|
|
|
+ $username= Env::get('oracle.username', 'root');
|
|
|
+ $password= Env::get('oracle.password', 'root');
|
|
|
+
|
|
|
+ $conn = new PDO("oci:dbname=//".$host.":".$port."/".$instance_name,$username,$password);// PDO方式
|
|
|
+ $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
+
|
|
|
+ $whereStr=buildQueryCond($cond);
|
|
|
+ $countQuery='SELECT count(*) as count FROM '.$tableName.' '.$whereStr;
|
|
|
+ $countRes= $conn -> query($countQuery)->fetch(PDO::FETCH_ASSOC);
|
|
|
|
|
|
+ if ($conn){
|
|
|
+ $conn = null;
|
|
|
+ }
|
|
|
+ // $response=[];
|
|
|
+ return (int)$countRes['COUNT'];
|
|
|
+ }
|
|
|
+ function buildQueryCond($cond){
|
|
|
+ $whereStr='';
|
|
|
+ foreach($cond as $key=>$val){
|
|
|
+
|
|
|
+ if( $key!='page' && $key!='limit' && $val[1]!=''){
|
|
|
+
|
|
|
+ if($val[0]=='like'){
|
|
|
+ if($whereStr==''){
|
|
|
+ $whereStr .='WHERE '.$key.' '.$val[0].' \'%'.$val[1].'%\'';
|
|
|
+ }else{
|
|
|
+ $whereStr .=' AND '.$key.' '.$val[0].' \'%'.$val[1].'%\'';
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if($whereStr==''){
|
|
|
+ $whereStr .='WHERE '.$key.' '.$val[0].' \''.$val[1].'\'';
|
|
|
+ }else{
|
|
|
+ $whereStr .=' AND '.$key.' '.$val[0].' \''.$val[1].'\'';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ return $whereStr;
|
|
|
+ }
|
|
|
|
|
|
- return $str;
|
|
|
- return mb_convert_encoding($str, 'UTF-8', 'GBK');
|
|
|
|
|
|
- }
|