36 lines
1007 B
PHP
36 lines
1007 B
PHP
<?php
|
|
header("Access-Control-Allow-Origin: *");
|
|
header("Content-Type: application/json; charset=UTF-8");
|
|
|
|
require_once '../config/database.php';
|
|
|
|
$database = new Database();
|
|
$db = $database->getConnection();
|
|
|
|
try {
|
|
$query = "SELECT id, nama, no_spbu, status, latitude, longitude FROM spbu ORDER BY nama ASC";
|
|
$stmt = $db->prepare($query);
|
|
$stmt->execute();
|
|
|
|
$spbu_arr = array();
|
|
|
|
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
|
$spbu_item = array(
|
|
"id" => $row['id'],
|
|
"nama" => $row['nama'],
|
|
"no_spbu" => $row['no_spbu'],
|
|
"status" => $row['status'],
|
|
"latitude" => floatval($row['latitude']),
|
|
"longitude" => floatval($row['longitude'])
|
|
);
|
|
array_push($spbu_arr, $spbu_item);
|
|
}
|
|
|
|
http_response_code(200);
|
|
echo json_encode($spbu_arr);
|
|
|
|
} catch(PDOException $e) {
|
|
http_response_code(500);
|
|
echo json_encode(array("message" => "Error: " . $e->getMessage()));
|
|
}
|
|
?>
|