-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery.php
More file actions
27 lines (26 loc) · 934 Bytes
/
query.php
File metadata and controls
27 lines (26 loc) · 934 Bytes
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
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "sensordata2";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$trp = mysqli_query($conn, "SELECT * from esp32data");
$rows = array();
while($r = mysqli_fetch_assoc($trp)) {
$rows[] = $r;
}
print json_encode($rows); //convert php data to json data
$json = json_encode($rows);
//$url1=$_SERVER['http://localhost/query.php'];
header("Refresh: 2");
header("Refresh: 2; url=../../../Users/mahas/Documents/GSB2/command/backend/routes/handler.js");
if (file_put_contents("../../../Users/mahas/Documents/GSB2/command/frontend/src/data.json", $json))
echo "JSON file created successfully...";
else
echo "Oops! Error creating json file...";
?>