<?php
require __DIR__ . '/vendor/autoload.php';

$app = require_once __DIR__ . '/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();

// 使用 .env 配置
$host = $_ENV['DB_HOST'] ?? getenv('DB_HOST');
$port = $_ENV['DB_PORT'] ?? getenv('DB_PORT');
$database = $_ENV['DB_DATABASE'] ?? getenv('DB_DATABASE');
$username = $_ENV['DB_USERNAME'] ?? getenv('DB_USERNAME');
$password = $_ENV['DB_PASSWORD'] ?? getenv('DB_PASSWORD');

$pdo = new PDO("mysql:host={$host};port={$port};dbname={$database};charset=utf8mb4", $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$stmt = $pdo->prepare('SELECT * FROM papers WHERE paper_id = ?');
$stmt->execute(['paper_1765263438_26997949']);
$paper = $stmt->fetch(PDO::FETCH_ASSOC);

if ($paper) {
    echo "=== 试卷基本信息 ===\n";
    print_r($paper);
    
    echo "\n=== 试卷题目 ===\n";
    $stmt2 = $pdo->prepare('SELECT * FROM paper_questions WHERE paper_id = ? ORDER BY question_number');
    $stmt2->execute(['paper_1765263438_26997949']);
    $questions = $stmt2->fetchAll(PDO::FETCH_ASSOC);
    
    echo "题目数量: " . count($questions) . "\n\n";
    foreach ($questions as $q) {
        echo "第{$q['question_number']}题:\n";
        echo "  ID: {$q['question_bank_id']}\n";
        echo "  内容: " . substr($q['question_text'], 0, 100) . "...\n";
        echo "  知识点: {$q['knowledge_point']}\n";
        echo "  题目类型: {$q['question_type']}\n";
        echo "  分值: {$q['score']}\n\n";
    }
} else {
    echo "未找到试卷\n";
}
