'localhost', 'username' => 'root', 'password' => '', 'database' => 'dms' ]; // Error handling $error_message = ''; // Create connection try { $conn = new mysqli( $db_config['host'], $db_config['username'], $db_config['password'], $db_config['database'] ); // Check connection if ($conn->connect_error) { throw new Exception("Connection failed: " . $conn->connect_error); } // Set charset to ensure proper encoding $conn->set_charset("utf8mb4"); } catch (Exception $e) { $error_message = $e->getMessage(); // Log the error error_log("Database Connection Error: " . $error_message); // Display user-friendly message echo '

Database Connection Error

We\'re having trouble connecting to the database. Please try again later.

If the problem persists, please contact the system administrator.

'; // Stop script execution die(); } ?>