
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");

// Database credentials
$host = 'localhost';
$db_name = 'erdovide_server';
$username = 'erdovide_igni725';
$password = 'v~RkX7UNxnM&';

try {
    // Connect to the database
    $conn = new PDO("mysql:host=$host;dbname=$db_name;charset=utf8", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    // Parse the requested URL
    $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);

    // Check if the requested endpoint is correct
    if ($path === '/public/api/news/erdovidek_2022_ksoft') {
        // Query the panit_feed table
        $query = "SELECT * FROM panit_feed2";
        $stmt = $conn->prepare($query);
        $stmt->execute();

        // Fetch data as an associative array
        $feeds = $stmt->fetchAll(PDO::FETCH_ASSOC);

        // Output the list directly as JSON
        echo json_encode($feeds);
    } else {
        // If the endpoint is incorrect, return an empty list
        echo json_encode([]);
    }
} catch (PDOException $e) {
    // Handle database connection errors
    http_response_code(500); // Internal Server Error
    echo json_encode([
        'error' => 'Database connection failed',
        'message' => $e->getMessage()
    ]);
}
?>

