<?php
// Database Connection Test
// Upload this file to your public_html folder and access it via: yoursite.com/test-db.php
echo "<h1>Database Connection Test</h1>";
echo "<p>Testing database connection...</p>";
// Database Configuration - UPDATE THESE WITH YOUR ACTUAL VALUES
$host = 'localhost';
$user = 'YOUR_DATABASE_USER'; // Change this
$pass = 'YOUR_DATABASE_PASSWORD'; // Change this
$name = 'YOUR_DATABASE_NAME'; // Change this
echo "<h3>Attempting to connect with:</h3>";
echo "Host: " . $host . "<br>";
echo "User: " . $user . "<br>";
echo "Database: " . $name . "<br><br>";
// Try connection
$conn = new mysqli($host, $user, $pass, $name);
if ($conn->connect_error) {
echo "<div style='color: red; padding: 20px; background: #ffebee; border: 2px solid red;'>";
echo "<h2>❌ CONNECTION FAILED</h2>";
echo "<p><strong>Error:</strong> " . $conn->connect_error . "</p>";
echo "<p><strong>Error Code:</strong> " . $conn->connect_errno . "</p>";
echo "<h3>Common Fixes:</h3>";
echo "<ul>";
echo "<li>Check that the database user exists in cPanel → MySQL Databases</li>";
echo "<li>Check that the database name is correct (might be prefixed with your cPanel username)</li>";
echo "<li>Check that the user is added to the database with ALL PRIVILEGES</li>";
echo "<li>Check that the password is correct</li>";
echo "</ul>";
echo "</div>";
} else {
echo "<div style='color: green; padding: 20px; background: #d4edda; border: 2px solid green;'>";
echo "<h2>✅ CONNECTION SUCCESSFUL!</h2>";
echo "<p>Database connection is working properly.</p>";
echo "<p>Server Version: " . $conn->server_info . "</p>";
// Check if orders table exists
$result = $conn->query("SHOW TABLES LIKE 'orders'");
if ($result->num_rows > 0) {
echo "<p><strong>✅ 'orders' table exists</strong></p>";
// Count orders
$count = $conn->query("SELECT COUNT(*) as count FROM orders")->fetch_assoc();
echo "<p>Number of orders in database: " . $count['count'] . "</p>";
} else {
echo "<p style='color: orange;'><strong>⚠️ 'orders' table NOT found</strong></p>";
echo "<p>You need to import the database/install.sql file via phpMyAdmin</p>";
}
echo "</div>";
$conn->close();
}
echo "<hr>";
echo "<p><strong>Next Steps:</strong></p>";
echo "<ol>";
echo "<li>If connection failed: Fix the credentials in this file and reload</li>";
echo "<li>If connection succeeded but no 'orders' table: Import database/install.sql</li>";
echo "<li>If everything is OK: Update config/database.php with the same credentials</li>";
echo "<li>Delete this test file for security!</li>";
echo "</ol>";
?>