34935-vm/api/stochastic_events.php
2025-10-14 04:07:36 +00:00

21 lines
559 B
PHP

<?php
header('Content-Type: application/json');
require_once '../db/config.php';
try {
$pdo = db();
$stmt = $pdo->query("SELECT id, event_name, probability, track_data FROM stochastic_events");
$events = $stmt->fetchAll();
// Decode the JSON track_data for each event
foreach ($events as &$event) {
$event['track_data'] = json_decode($event['track_data']);
}
echo json_encode($events);
} catch (PDOException $e) {
http_response_code(500);
echo json_encode(['error' => 'Database error: ' . $e->getMessage()]);
}