Files
TUGAS_SIG_JOHANESSATRIACHRI…/Projek SPBU 24 JAM/Projek/api/get_roads.php
T

22 lines
612 B
PHP

<?php
require_once 'config.php';
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
try {
$db = getDB();
$stmt = $db->query('SELECT id, name, status, length, coordinates, created_at FROM roads ORDER BY created_at DESC');
$roads = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode([
'success' => true,
'roads' => $roads
]);
} catch (Exception $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}
} else {
http_response_code(405);
echo json_encode(['error' => 'Method not allowed']);
}
?>