<?php
/**
 * debug_chatbot_charset.php
 * ⚠️ শুধু Debug-এর জন্য — chatbot_faq Table-এর Charset আর
 * আসল Data ঠিক আছে কিনা তা দেখার জন্য
 */
include __DIR__ . "/deepanshu/conn.php";
header('Content-Type: text/plain; charset=utf-8');

echo "=== Table-এর Charset Check ===\n";
$charsetResult = $conn->query("SELECT CCSA.character_set_name, CCSA.collation_name
    FROM information_schema.`TABLES` T,
         information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
    WHERE CCSA.collation_name = T.table_collation
    AND T.table_schema = DATABASE()
    AND T.table_name = 'chatbot_faq'");
if ($charsetResult) {
    $row = $charsetResult->fetch_assoc();
    echo "Table-Charset: " . ($row['character_set_name'] ?? 'পাওয়া যায়নি') . "\n";
    echo "Table-Collation: " . ($row['collation_name'] ?? 'পাওয়া যায়নি') . "\n\n";
}

echo "=== Connection-Charset (এই মুহূর্তে) ===\n";
echo "PHP set_charset প্রয়োগের আগে: " . $conn->character_set_name() . "\n";
$conn->set_charset("utf8mb4");
echo "PHP set_charset প্রয়োগের পরে: " . $conn->character_set_name() . "\n\n";

echo "=== আসল Data (Raw, Database থেকে সরাসরি) ===\n";
$dataResult = $conn->query("SELECT id, keywords, answer FROM chatbot_faq LIMIT 3");
if ($dataResult && $dataResult->num_rows > 0) {
    while ($row = $dataResult->fetch_assoc()) {
        echo "ID: {$row['id']}\n";
        echo "Keywords: {$row['keywords']}\n";
        echo "Answer: {$row['answer']}\n";
        echo "Answer-এর Byte-Length: " . strlen($row['answer']) . "\n";
        echo "---\n";
    }
} else {
    echo "chatbot_faq Table-এ কোনো Data নেই, অথবা Table-ই নেই।\n";
}
