24 lines
1.0 KiB
PHP
24 lines
1.0 KiB
PHP
<?php
|
|
// ── GET SPBU ──────────────────────────────────────────────────────────────────
|
|
require_once __DIR__ . '/config.php';
|
|
|
|
header('Content-Type: application/json');
|
|
header('Access-Control-Allow-Origin: *');
|
|
header('Access-Control-Allow-Methods: GET, OPTIONS');
|
|
header('Access-Control-Allow-Headers: Content-Type');
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
|
http_response_code(200);
|
|
exit();
|
|
}
|
|
|
|
// ── AMBIL DATA ────────────────────────────────────────────────────────────────
|
|
try {
|
|
$stmt = $pdo->query("SELECT * FROM spbu ORDER BY created_at DESC");
|
|
$rows = $stmt->fetchAll();
|
|
echo json_encode($rows);
|
|
} catch (PDOException $e) {
|
|
http_response_code(500);
|
|
echo json_encode(['error' => 'Gagal mengambil data: ' . $e->getMessage()]);
|
|
}
|