<?php
ini_set("precision", "4");
class MyDB extends SQLite3
{
   function __construct()
   {
			//$this->open('C:/Users/Administrator/Desktop/workFile/ElecWaterPrj/水文协议SL651 配置软件20220120/DB/SL651.sqlite.db3');
			$this->open('./SL651.sqlite.db3');
   }
}
$con = new MyDB();
if (!$con) {
   echo $con->lastErrorMsg();
}

$sql = "SELECT * FROM dataInfo ORDER by reportTime DESC LIMIT 0,4;";
$result = $con->query($sql);
if (!$result) {
   printf("Error: SELECT DB ERR\n");
   exit();
}

$news = [];
$i=0;

//if ($result->num_rows > 0) 
{

    while($row = $result->fetchArray(SQLITE3_ASSOC)) {

		if ($row['pcode']== '38'||$row['pcode']== '3C' ) {
			$dataTime=$row['dataTime'];
			$reportTime=$row['reportTime'];
			$devID=$row['devID'];
			$pcode=$row['pcode'];
			$pvalue= $row['pvalue'];
			$news[$i] = array("dataTime"=>"$dataTime","reportTime"=>"$reportTime","devID"=>"$devID","pcode"=>"$pcode","pvalue"=>"$pvalue");
			$i=$i+1;
		}
    }
} 

$datalist = $news;

echo json_encode($datalist,JSON_UNESCAPED_UNICODE);
?>