|
@@ -1281,22 +1281,20 @@ use PDO;
|
|
|
}
|
|
|
$start=($cond['page']-1)*$cond['limit'];
|
|
|
$end=$cond['page']*$cond['limit'];
|
|
|
- $whereStr=buildQueryCond($cond);
|
|
|
- $sql = 'SELECT * FROM ( SELECT '.$field.',ROWNUM RN FROM (SELECT * FROM '.$tableName.' '.$whereStr.' ORDER BY ID DESC) a WHERE ROWNUM <='.$end.' ) WHERE RN >='. $start;
|
|
|
- // var_dump($sql);
|
|
|
+ $whereStr=buildQueryCond2($cond);
|
|
|
+ // $sql = 'SELECT * FROM ( SELECT '.$field.',ROWNUM RN FROM (SELECT * FROM '.$tableName.' '.$whereStr.' ORDER BY ID DESC) a WHERE ROWNUM <='.$end.' ) WHERE RN >='. $start;
|
|
|
+ $sql='SELECT * FROM ( SELECT '.$field.',ROWNUM RN FROM '.$tableName.' WHERE ROWNUM <='.$end.' '.$whereStr.' ) WHERE RN >='. $start;
|
|
|
+ // var_dump($sql);
|
|
|
// 查询并渲染
|
|
|
$stid = oci_parse($conn, $sql);
|
|
|
- // var_dump($stid);
|
|
|
$r = oci_execute($stid);
|
|
|
- // var_dump($r);
|
|
|
- // $rows=[];
|
|
|
+ $rows=[];
|
|
|
while($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
|
|
|
|
|
|
$rows[]=$row;
|
|
|
}
|
|
|
- // var_dump($rows);
|
|
|
oci_free_statement($stid);
|
|
|
-
|
|
|
+ return $rows;
|
|
|
// $conn = new PDO("oci:dbname=//".$host.":".$port."/".$instance_name,$username,$password);// PDO方式
|
|
|
// $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
|
@@ -1314,7 +1312,7 @@ use PDO;
|
|
|
// $conn = null;
|
|
|
// }
|
|
|
// $rows=[];
|
|
|
- return $rows;
|
|
|
+
|
|
|
}
|
|
|
/**
|
|
|
* 查询oracle数据库 count
|
|
@@ -1368,6 +1366,7 @@ use PDO;
|
|
|
$whereStr=buildQueryCond($cond);
|
|
|
$countQuery='SELECT count(*) as count FROM '.$tableName.' '.$whereStr;
|
|
|
// var_dump($countQuery);
|
|
|
+ // return 1111;
|
|
|
$countRes= $conn -> query($countQuery)->fetch(PDO::FETCH_ASSOC);
|
|
|
|
|
|
if ($conn){
|
|
@@ -1375,12 +1374,21 @@ use PDO;
|
|
|
}
|
|
|
return (int)$countRes['COUNT'];
|
|
|
}
|
|
|
+
|
|
|
function buildQueryCond($cond){
|
|
|
$whereStr='';
|
|
|
foreach($cond as $key=>$val){
|
|
|
|
|
|
if( $key!='page' && $key!='limit' && $val[1]!=''){
|
|
|
-
|
|
|
+ if($key=='_string'){
|
|
|
+ if($whereStr==''){
|
|
|
+ $whereStr .='WHERE '.$val;
|
|
|
+ }else{
|
|
|
+ $whereStr .=' AND '.$val;
|
|
|
+ }
|
|
|
+
|
|
|
+ continue;
|
|
|
+ }
|
|
|
if($val[0]=='like'){
|
|
|
if($whereStr==''){
|
|
|
$whereStr .='WHERE '.$key.' '.$val[0].' \'%'.$val[1].'%\'';
|
|
@@ -1405,4 +1413,26 @@ use PDO;
|
|
|
return $whereStr;
|
|
|
}
|
|
|
|
|
|
+ function buildQueryCond2($cond){
|
|
|
+ $whereStr='';
|
|
|
+ foreach($cond as $key=>$val){
|
|
|
+
|
|
|
+ if( $key!='page' && $key!='limit' && $val[1]!=''){
|
|
|
+ if($key=='_string'){
|
|
|
+ $whereStr .=' AND '.$val;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if($val[0]=='like'){
|
|
|
+ $whereStr .=' AND '.$key.' '.$val[0].' \'%'.$val[1].'%\'';
|
|
|
+ }else if($val[0]=='timeRange'){
|
|
|
+ $whereStr .=' AND '.$key.' >= to_date(\''.$val[1].'\', \'yyyy-mm-dd hh24:mi:ss\') AND '.$key.' <= to_date(\''.$val[2].'\', \'yyyy-mm-dd hh24:mi:ss\')';
|
|
|
+ }else{
|
|
|
+ $whereStr .=' AND '.$key.' '.$val[0].' \''.$val[1].'\'';
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $whereStr;
|
|
|
+ }
|
|
|
+
|
|
|
|