Sindbad~EG File Manager
<?php
/**
* Database Connection Test Utility
* Use this file to diagnose database connection issues in production
*/
require_once 'config/config.php';
echo "<!DOCTYPE html>";
echo "<html><head><title>Database Connection Test</title>";
echo "<style>
body { font-family: Arial, sans-serif; margin: 20px; }
.success { color: green; }
.error { color: red; }
.warning { color: orange; }
.info { color: blue; }
.test-section { margin: 20px 0; padding: 15px; border: 1px solid #ddd; border-radius: 5px; }
.status-item { margin: 10px 0; }
</style></head><body>";
echo "<h1>COP News Portal - Database Connection Test</h1>";
try {
$database = new Database();
echo "<div class='test-section'>";
echo "<h2>Connection Status Check</h2>";
$status = $database->getConnectionStatus();
echo "<div class='status-item'>";
echo "<strong>Host Reachable:</strong> ";
if ($status['host_reachable']) {
echo "<span class='success'>✓ YES</span>";
} else {
echo "<span class='error'>✗ NO</span>";
}
echo "</div>";
echo "<div class='status-item'>";
echo "<strong>Credentials Valid:</strong> ";
if ($status['credentials_valid']) {
echo "<span class='success'>✓ YES</span>";
} else {
echo "<span class='error'>✗ NO</span>";
}
echo "</div>";
echo "<div class='status-item'>";
echo "<strong>Database Exists:</strong> ";
if ($status['database_exists']) {
echo "<span class='success'>✓ YES</span>";
} else {
echo "<span class='error'>✗ NO</span>";
}
echo "</div>";
echo "<div class='status-item'>";
echo "<strong>Connection Successful:</strong> ";
if ($status['connection_successful']) {
echo "<span class='success'>✓ YES</span>";
} else {
echo "<span class='error'>✗ NO</span>";
}
echo "</div>";
if (!empty($status['error_message'])) {
echo "<div class='status-item'>";
echo "<strong>Error Message:</strong> <span class='error'>" . htmlspecialchars($status['error_message']) . "</span>";
echo "</div>";
}
echo "</div>";
// Show configuration details
echo "<div class='test-section'>";
echo "<h2>Database Configuration</h2>";
echo "<div class='status-item'><strong>Host:</strong> <span class='info'>localhost</span></div>";
echo "<div class='status-item'><strong>Database:</strong> <span class='info'>copmadinaarea_cop_news_portal</span></div>";
echo "<div class='status-item'><strong>Username:</strong> <span class='info'>copmadinaarea_nabibo</span></div>";
echo "<div class='status-item'><strong>Password:</strong> <span class='info'>[HIDDEN]</span></div>";
echo "</div>";
// Test actual connection
echo "<div class='test-section'>";
echo "<h2>Connection Test</h2>";
try {
$conn = $database->getConnection();
echo "<div class='status-item'><span class='success'>✓ Database connection successful!</span></div>";
// Test a simple query
$stmt = $conn->query("SELECT COUNT(*) as count FROM users");
$result = $stmt->fetch();
echo "<div class='status-item'><span class='success'>✓ Query test successful - Found " . $result['count'] . " users</span></div>";
} catch (Exception $e) {
echo "<div class='status-item'><span class='error'>✗ Connection failed: " . htmlspecialchars($e->getMessage()) . "</span></div>";
}
echo "</div>";
// Troubleshooting guide
echo "<div class='test-section'>";
echo "<h2>Troubleshooting Guide</h2>";
echo "<div class='status-item'>";
echo "<strong>If Host is not reachable:</strong><br>";
echo "• Check if MySQL service is running<br>";
echo "• Verify the host address is correct<br>";
echo "• Check firewall settings (port 3306)<br>";
echo "</div>";
echo "<div class='status-item'>";
echo "<strong>If Credentials are invalid:</strong><br>";
echo "• Verify username: copmadinaarea_nabibo<br>";
echo "• Verify password: copmadinaarea_nabibo<br>";
echo "• Check if user exists in MySQL<br>";
echo "• Run: CREATE USER 'copmadinaarea_nabibo'@'localhost' IDENTIFIED BY 'copmadinaarea_nabibo';<br>";
echo "</div>";
echo "<div class='status-item'>";
echo "<strong>If Database doesn't exist:</strong><br>";
echo "• Create database: CREATE DATABASE copmadinaarea_cop_news_portal;<br>";
echo "• Grant privileges: GRANT ALL PRIVILEGES ON copmadinaarea_cop_news_portal.* TO 'copmadinaarea_nabibo'@'localhost';<br>";
echo "• Run: FLUSH PRIVILEGES;<br>";
echo "</div>";
echo "</div>";
} catch (Exception $e) {
echo "<div class='test-section'>";
echo "<h2 class='error'>Critical Error</h2>";
echo "<p class='error'>Failed to initialize database class: " . htmlspecialchars($e->getMessage()) . "</p>";
echo "</div>";
}
echo "<div class='test-section'>";
echo "<h2>Next Steps</h2>";
echo "<p>1. Fix any issues shown above</p>";
echo "<p>2. Delete this test file after resolving issues</p>";
echo "<p>3. <a href='index.php'>Return to Application</a></p>";
echo "</div>";
echo "</body></html>";
?>
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists