initial commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?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();
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user