<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

echo "<h1>🔍 MySQL Credential Checker</h1>";
echo "<p><strong>This script helps find the correct MySQL credentials</strong></p>";

// Try different possible credentials
$hostname = 'localhost';
$possible_users = [
    'mahamusa',
    'mahamusa_dev',
    'mahamusa_user',
    'mahamusa_admin',
    'root'
];

$possible_databases = [
    'mahamusa_db',
    'mahamusa',
    'login-table',
    'login_table'
];

$possible_passwords = [
    'tCG!c&lpxW8Q',
    '',  // empty
];

echo "<h2>Testing Combinations:</h2>";
echo "<table border='1' cellpadding='10'>";
echo "<tr><th>User</th><th>Password</th><th>Database</th><th>Result</th></tr>";

foreach ($possible_users as $user) {
    foreach ($possible_passwords as $pwd) {
        foreach ($possible_databases as $db) {
            $result = "❌ Failed";
            $error_msg = "";
            
            try {
                $conn = new mysqli($hostname, $user, $pwd, $db);
                
                if ($conn->connect_error) {
                    $error_msg = $conn->connect_error;
                } else {
                    $result = "✅ SUCCESS!";
                    
                    // Show some info if connected
                    $tables = $conn->query("SHOW TABLES");
                    $table_count = $tables ? $tables->num_rows : 0;
                    $error_msg = "Tables found: $table_count";
                    
                    $conn->close();
                }
            } catch (Exception $e) {
                $error_msg = $e->getMessage();
            }
            
            $pwd_display = empty($pwd) ? "(empty)" : "***";
            echo "<tr>";
            echo "<td>$user</td>";
            echo "<td>$pwd_display</td>";
            echo "<td>$db</td>";
            echo "<td>$result<br><small>$error_msg</small></td>";
            echo "</tr>";
        }
    }
}

echo "</table>";

echo "<h2>📝 Instructions:</h2>";
echo "<p>Look for any row with <strong>✅ SUCCESS!</strong></p>";
echo "<p>When you find the working combination:</p>";
echo "<ol>";
echo "<li>Note the User, Password, and Database</li>";
echo "<li>Update db_config.php with these values</li>";
echo "<li>Upload updated db_config.php to cPanel</li>";
echo "<li>Test again</li>";
echo "</ol>";

echo "<hr>";
echo "<p><a href='test_error_simple.php'>← Back to Simple Test</a></p>";
?>
