Files
UAS_WEBGIS_CindyDyraIslamay…/01SPBU/SPBU/ambil.php
T
2026-06-10 19:20:46 +07:00

35 lines
717 B
PHP

<?php
header('Content-Type: application/json');
try {
require_once __DIR__ . '/../koneksi.php';
// Cek koneksi
if (!isset($conn) || $conn->connect_error) {
throw new Exception("Database connection failed");
}
$result = $conn->query("SELECT * FROM spbu ORDER BY created_at DESC");
if (!$result) {
throw new Exception("Query failed: " . $conn->error);
}
$data = array();
while ($row = $result->fetch_assoc()) {
$data[] = $row;
}
echo json_encode($data);
} catch (Exception $e) {
echo json_encode([
'error' => true,
'message' => $e->getMessage()
]);
}
if (isset($conn)) {
$conn->close();
}
?>