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(); } ?>