<?php
header("Content-Type: application/json");
include 'db.php';

try {
    $stmt = $pdo->query("SELECT id, name FROM categories ORDER BY name");
    $categories = $stmt->fetchAll(PDO::FETCH_ASSOC);
    echo json_encode($categories);
} catch (Exception $e) {
    echo json_encode(["error" => $e->getMessage()]);
}
?>