getDataTable.php

mail@pastecode.io avatar
unknown
php
a month ago
391 B
0
Indexable
Never
<?php
// Koneksi ke database
require('koneksi.php');
$sql = "SELECT * FROM sensor ORDER BY time_stamp DESC ";

$result = $koneksi->query($sql);

if ($result->num_rows > 0) {
    $data = array();
    while ($row = $result->fetch_assoc()) {
        $data[] = $row;
    }
    echo json_encode($data);
} else {
    echo json_encode([]);
}

// Tutup koneksi
$koneksi->close();
Leave a Comment