-
Notifications
You must be signed in to change notification settings - Fork 0
/
jiexi.php
43 lines (36 loc) · 1.9 KB
/
jiexi.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
include("_func_info.php");
//$jsonReceiveData = json_decode($_POST);
//print_r($_POST);
//$tb_device = "device";
//$tb_user = "user";
//$tb_data = "data";
//$dbcon=mysqli_connect($dbhost, $dbaccount, $dbpassword, $dbname) or die("Fail to connect to database: ".mysqli_connect_error());
//$dbcon=mysql_connect("localhost","root") or die("数据库服务器连接错误".mysql_error());
//mysql_select_db("ddp",$dbcon) or die("数据库访问错误".mysql_error());
$a=file_get_contents('php://input');
$get_json=json_decode($a);
$deviceid=(int)($get_json->apikey);
$description=addslashes($get_json->datastreams[0]->description);
$data=(double)($get_json->datastreams[0]->current_value);
date_default_timezone_set('Asia/Hong_Kong');
$time=date("Y-m-d h:i:s");
$unit=addslashes($get_json->datastreams[0]->unit);
$result = mysqli_query($dbcon, "select * from $tb_datatype where description='$description' and unit='$unit';");
if (mysqli_num_rows($result) == 0) {
mysqli_query($dbcon, "insert into $tb_dataype(id, description, unit) values(null, '$description', '$unit');");
$result = mysqli_query($dbcon, "select id from $tb_datatype where description='$description' and unit='$unit';");
$row = mysqli_fetch_array($result);
$typeid = $row['id'];
mysqli_query($dbcon, "insert into $tb_data(deviceid, data, time, typeid) values($deviceid, '$data', $time, $typeid);");
}
else {
$row = mysqli_fetch_array($result);
$typeid = $row['id'];
mysqli_query($dbcon, "insert into $tb_data(deviceid, data, time, typeid) values($deviceid, '$data', '$time', $typeid);");
}
/*
$sql=mysqli_query( $dbcon,"insert into $tb_data(deviceid,description,data,time,unit) values($deviceid,'$description','$data','$time','$unit');") or die("Fail to Insert");
$sql1=mysqli_query( $dbcon,"insert into testjson(json) values('$a');") or die("Fail to Insert a a a ");
*/
?>