Initial commit untuk UAS SIG
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
// ============================================
|
||||
// read_jalan.php — SELECT semua data Jalan
|
||||
// ============================================
|
||||
|
||||
header('Content-Type: application/json');
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Access-Control-Allow-Methods: 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_jalan, status, panjang, geom FROM jalan 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;
|
||||
}
|
||||
|
||||
$jalanList = [];
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$jalanList[] = [
|
||||
'id' => (int) $row['id'],
|
||||
'nama_jalan' => $row['nama_jalan'],
|
||||
'status' => $row['status'],
|
||||
'panjang' => (float) $row['panjang'],
|
||||
'geom' => json_decode($row['geom'], true),
|
||||
];
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'count' => count($jalanList),
|
||||
'data' => $jalanList,
|
||||
]);
|
||||
|
||||
$result->free();
|
||||
$conn->close();
|
||||
Reference in New Issue
Block a user