<?php
require_once '../config.php';

try {
    // Attempt connection
    $dsn = "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=utf8mb4";
    $pdo = new PDO($dsn, DB_USER, DB_PASS);
    echo "<h2 style='color:green'>Database Connection Successful!</h2>";
    echo "<p>Connected to <b>" . DB_NAME . "</b> at " . DB_HOST . ".</p>";

    // Check tables
    $tables = $pdo->query("SHOW TABLES")->fetchAll(PDO::FETCH_COLUMN);
    echo "<h3>Tables Found:</h3><ul>";
    foreach ($tables as $t) {
        echo "<li>$t</li>";
    }
    echo "</ul>";

} catch (PDOException $e) {
    echo "<h2 style='color:red'>Connection Failed</h2>";
    echo "<p>" . $e->getMessage() . "</p>";
    echo "<hr>";
    echo "<h4>Debug Info:</h4>";
    echo "Host: " . DB_HOST . "<br>";
    echo "User: " . DB_USER . "<br>";
    echo "DB Name: " . DB_NAME . "<br>";
}
?>