
<?php
require_once 'config.php';
header('Content-Type: application/json; charset=utf-8');
try {
    $pdo->exec("CREATE TABLE IF NOT EXISTS faq_items (id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, question VARCHAR(255) NOT NULL, answer MEDIUMTEXT NOT NULL, is_active TINYINT(1) NOT NULL DEFAULT 1, display_order INT NOT NULL DEFAULT 0, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, KEY idx_faq_active_order (is_active, display_order, id)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci");
    $st=$pdo->query("SELECT id, question, answer FROM faq_items WHERE is_active=1 ORDER BY display_order ASC, id ASC LIMIT 80");
    echo json_encode(['ok'=>true,'data'=>['items'=>$st->fetchAll(PDO::FETCH_ASSOC)]], JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
} catch (Throwable $e) { echo json_encode(['ok'=>false,'error'=>$e->getMessage()], JSON_UNESCAPED_UNICODE); }
