<?php
header('Content-Type: application/json; charset=utf-8');
require_once __DIR__ . '/../config.php';
try {
    $db = getDB();
    $stmt = $db->query("DESCRIBE regs2");
    $cols = $stmt->fetchAll(PDO::FETCH_ASSOC);
    $stmt2 = $db->query("SELECT * FROM regs2 ORDER BY idreg DESC LIMIT 1");
    $sample = $stmt2->fetchAll(PDO::FETCH_ASSOC);
    echo json_encode(['columns' => $cols, 'sample' => $sample], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
} catch (Throwable $e) {
    echo json_encode(['error' => $e->getMessage()]);
}
