56 lines
1.4 KiB
PHP
56 lines
1.4 KiB
PHP
//fetch_data2
|
|
<?php
|
|
$servername = "localhost";
|
|
$username = "root";
|
|
$password = "devbas2603";
|
|
$dbname = "tugas_akhir";
|
|
$conn = new mysqli($servername, $username, $password, $dbname);
|
|
if ($conn->connect_error) {
|
|
die("Connection failed: " . $conn->connect_error);
|
|
}
|
|
|
|
$sql = "SELECT voltage, power, current, energy, timestamp FROM sensor_reference1 ORDER BY id DESC LIMIT 1";
|
|
$result = $conn->query($sql);
|
|
$data = array();
|
|
if ($result->num_rows > 0) {
|
|
// Output data of each row
|
|
while ($row = $result->fetch_assoc()) {
|
|
$data = array(
|
|
'voltage' => $row['voltage'],
|
|
'current' => $row['current'],
|
|
'power' => $row['power'],
|
|
'energy' => $row['energy']
|
|
);
|
|
}
|
|
}
|
|
$conn->close();
|
|
header('Content-Type: application/json');
|
|
echo json_encode($data);
|
|
?>
|
|
|
|
//fetch_data2
|
|
<?php
|
|
$servername = "localhost";
|
|
$username = "root";
|
|
$password = "devbas2603";
|
|
$dbname = "tugas_akhir";
|
|
$conn = new mysqli($servername, $username, $password, $dbname);
|
|
if ($conn->connect_error) {
|
|
die("Connection failed: " . $conn->connect_error);
|
|
}
|
|
$sql = "SELECT saldo, biaya, timestamp FROM biaya_reference ORDER BY id DESC LIMIT 1";
|
|
$result = $conn->query($sql);
|
|
$data = array();
|
|
if ($result->num_rows > 0) {
|
|
while ($row = $result->fetch_assoc()) {
|
|
$data = array(
|
|
'saldo' => $row['saldo'],
|
|
'biaya' => $row['biaya']
|
|
);
|
|
}
|
|
}
|
|
$conn->close();
|
|
header('Content-Type: application/json');
|
|
echo json_encode($data);
|
|
?>
|