<?php
// pievieno datubazes savienojumu
require_once 'db_connection.php';

// nolasam datumu no GET pieprasijuma vai iziet ja tas nav noradits
$date = isset($_GET['date']) ? $_GET['date'] : die('Datums nav noradits');

// sagatavo SQL pieprasijumu, lai iegutu notikumus konkretajam datumam
$sql = "SELECT id, title, description FROM events WHERE event_date = ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$date]);

// iegust notikumus un atgriez tos JSON formata
$events = $stmt->fetchAll(PDO::FETCH_ASSOC);

header('Content-Type: application/json');
echo json_encode($events);
?>
