Initial commit untuk UAS SIG

This commit is contained in:
z0rayy
2026-06-08 21:16:23 +07:00
commit c90ce9aedc
39 changed files with 7105 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
<?php
// ============================================
// read.php — SELECT semua data SPBU
// ============================================
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET');
// Hanya terima metode GET
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
http_response_code(405);
echo json_encode(['success' => false, 'message' => 'Metode tidak diizinkan.']);
exit;
}
require_once __DIR__ . '/koneksi.php';
$conn = getConnection();
$sql = "SELECT id, nama, no_spbu, status, latitude, longitude FROM spbu ORDER BY created_at DESC";
$result = $conn->query($sql);
if (!$result) {
http_response_code(500);
echo json_encode(['success' => false, 'message' => 'Query gagal: ' . $conn->error]);
$conn->close();
exit;
}
$spbuList = [];
while ($row = $result->fetch_assoc()) {
$spbuList[] = [
'id' => (int) $row['id'],
'nama' => $row['nama'],
'no_spbu' => $row['no_spbu'],
'status' => $row['status'],
'latitude' => (float) $row['latitude'],
'longitude' => (float) $row['longitude'],
];
}
echo json_encode([
'success' => true,
'count' => count($spbuList),
'data' => $spbuList,
]);
$result->free();
$conn->close();