<?php
echo "Testing database connection...<br>";
echo "Current directory: " . __DIR__ . "<br><br>";

// Test direct connection
try {
    $pdo_test = new PDO(
        "mysql:host=localhost;dbname=attendance_system;charset=utf8mb4",
        "root",
        "",
        [
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
        ]
    );
    
    echo "✅ Direct database connection successful!<br>";
    
    // Test query
    $stmt = $pdo_test->query("SELECT COUNT(*) as count FROM users");
    $result = $stmt->fetch();
    echo "✅ Database query successful!<br>";
    echo "Total users: " . $result['count'] . "<br>";
    
} catch (PDOException $e) {
    echo "❌ Database connection failed: " . $e->getMessage() . "<br>";
}

echo "<br>Now testing includes/database.php...<br>";

$path = __DIR__ . '/includes/database.php';
echo "Looking for file at: " . $path . "<br>";

if (file_exists($path)) {
    echo "✅ File exists!<br>";
    
    // Include the file
    require_once $path;
    
    if (isset($pdo)) {
        echo "✅ \$pdo variable is set!<br>";
        
        try {
            $stmt = $pdo->query("SELECT 1");
            echo "✅ Database query through includes/database.php works!<br>";
        } catch (Exception $e) {
            echo "❌ Query failed: " . $e->getMessage() . "<br>";
        }
    } else {
        echo "❌ \$pdo variable is NOT set!<br>";
    }
} else {
    echo "❌ File does NOT exist!<br>";
}
?>