/home3/bmscom/apps.theaffluentman.com/test-connection.php
<?php
// Simple Database Test - No External Files
// This test doesn't include any config files, so it will work even if they have errors
echo "<!DOCTYPE html><html><head><style>
body { font-family: Arial, sans-serif; padding: 20px; background: #f5f5f5; }
.box { padding: 20px; margin: 20px 0; border-radius: 8px; }
.red { background: #ffebee; border: 2px solid #f44336; color: #d32f2f; }
.green { background: #d4edda; border: 2px solid #4caf50; color: #155724; }
.orange { background: #fff3cd; border: 2px solid #ffc107; color: #856404; }
h1 { color: #333; }
code { background: #f0f0f0; padding: 2px 6px; border-radius: 3px; }
</style></head><body>";
echo "<h1>🔧 Simple Database Connection Test</h1>";
// EDIT THESE VALUES WITH YOUR ACTUAL DATABASE INFO
$db_host = 'localhost';
$db_user = 'YOUR_DB_USER'; // ← CHANGE THIS
$db_pass = 'YOUR_DB_PASSWORD'; // ← CHANGE THIS
$db_name = 'YOUR_DB_NAME'; // ← CHANGE THIS
echo "<div class='box orange'>";
echo "<h2>📋 Configuration Check</h2>";
echo "<p>Before testing, make sure you've edited this file and replaced:</p>";
echo "<ul>";
echo "<li><code>YOUR_DB_USER</code> with your actual database username</li>";
echo "<li><code>YOUR_DB_PASSWORD</code> with your actual database password</li>";
echo "<li><code>YOUR_DB_NAME</code> with your actual database name</li>";
echo "</ul>";
echo "</div>";
echo "<div class='box'>";
echo "<h2>🔌 Attempting Connection...</h2>";
echo "<p><strong>Host:</strong> $db_host</p>";
echo "<p><strong>User:</strong> $db_user</p>";
echo "<p><strong>Database:</strong> $db_name</p>";
echo "</div>";
// Check if values were changed
if ($db_user === 'YOUR_DB_USER' || $db_pass === 'YOUR_DB_PASSWORD' || $db_name === 'YOUR_DB_NAME') {
echo "<div class='box red'>";
echo "<h2>⚠️ NOT CONFIGURED YET!</h2>";
echo "<p>You need to edit this file first and replace the placeholder values with your actual database credentials from cPanel.</p>";
echo "<h3>How to find your database info in cPanel:</h3>";
echo "<ol>";
echo "<li>Login to cPanel</li>";
echo "<li>Go to <strong>MySQL Databases</strong></li>";
echo "<li>Look for <strong>Current Databases</strong> section - copy the database name</li>";
echo "<li>Look for <strong>Current Users</strong> section - copy the username</li>";
echo "<li>Note: Names are usually prefixed like <code>cpaneluser_dbname</code></li>";
echo "</ol>";
echo "</div>";
} else {
// Try to connect
$conn = @new mysqli($db_host, $db_user, $db_pass, $db_name);
if ($conn->connect_error) {
echo "<div class='box red'>";
echo "<h2>❌ CONNECTION FAILED</h2>";
echo "<p><strong>Error:</strong> " . htmlspecialchars($conn->connect_error) . "</p>";
echo "<p><strong>Error Number:</strong> " . $conn->connect_errno . "</p>";
echo "<h3>💡 How to Fix This Error:</h3>";
if ($conn->connect_errno == 1045) {
echo "<p><strong>Error 1045 - Access Denied</strong></p>";
echo "<ul>";
echo "<li>❌ Wrong username or password</li>";
echo "<li>✅ Fix: Go to cPanel → MySQL Databases and verify your username</li>";
echo "<li>✅ If password is wrong, change it in cPanel and update this file</li>";
echo "</ul>";
} elseif ($conn->connect_errno == 1049) {
echo "<p><strong>Error 1049 - Unknown Database</strong></p>";
echo "<ul>";
echo "<li>❌ Database name is wrong or doesn't exist</li>";
echo "<li>✅ Fix: Check the exact database name in cPanel → MySQL Databases</li>";
echo "<li>✅ Remember: database names are usually prefixed with your cPanel username</li>";
echo "</ul>";
} elseif ($conn->connect_errno == 2002) {
echo "<p><strong>Error 2002 - Can't Connect to MySQL Server</strong></p>";
echo "<ul>";
echo "<li>❌ Host is wrong (should be 'localhost' for most shared hosting)</li>";
echo "<li>✅ Fix: Try using 'localhost' or ask your hosting provider</li>";
echo "</ul>";
} else {
echo "<ul>";
echo "<li>Contact your hosting support with this error</li>";
echo "<li>Verify that MySQL service is running</li>";
echo "</ul>";
}
echo "</div>";
} else {
echo "<div class='box green'>";
echo "<h2>✅ CONNECTION SUCCESSFUL!</h2>";
echo "<p>Database connection is working perfectly! 🎉</p>";
echo "<p><strong>MySQL Version:</strong> " . $conn->server_info . "</p>";
// Check for orders table
$result = @$conn->query("SHOW TABLES LIKE 'orders'");
if ($result && $result->num_rows > 0) {
echo "<p><strong>✅ Table 'orders' exists</strong></p>";
// Try to count
$count_result = @$conn->query("SELECT COUNT(*) as count FROM orders");
if ($count_result) {
$count = $count_result->fetch_assoc();
echo "<p><strong>Orders in database:</strong> " . $count['count'] . "</p>";
}
} else {
echo "<div class='box orange' style='margin-top: 20px;'>";
echo "<h3>⚠️ Table 'orders' Not Found</h3>";
echo "<p>You need to import the database structure:</p>";
echo "<ol>";
echo "<li>Go to cPanel → phpMyAdmin</li>";
echo "<li>Select your database (<code>$db_name</code>)</li>";
echo "<li>Click 'Import' tab</li>";
echo "<li>Download <code>database/install.sql</code> from File Manager</li>";
echo "<li>Upload and import it</li>";
echo "</ol>";
echo "</div>";
}
echo "<h3>✅ Next Steps:</h3>";
echo "<ol>";
echo "<li>Copy these exact credentials to <code>config/database.php</code>:</li>";
echo "<li><code>define('DB_HOST', '$db_host');</code></li>";
echo "<li><code>define('DB_USER', '$db_user');</code></li>";
echo "<li><code>define('DB_PASS', '$db_pass');</code></li>";
echo "<li><code>define('DB_NAME', '$db_name');</code></li>";
echo "<li>Import the database table if you haven't already</li>";
echo "<li>Try logging in at: <code>apps.theaffluentman.com/admin/</code></li>";
echo "<li><strong>Delete this test file for security!</strong></li>";
echo "</ol>";
echo "</div>";
$conn->close();
}
}
echo "</body></html>";
?>