What's the best practice for handling the 'Unknown database' error in a PHP application to improve user experience?

Responsive Ad Header

Question

Grade: Education Subject: Support
What's the best practice for handling the 'Unknown database' error in a PHP application to improve user experience?
Asked by:
115 Viewed 115 Answers
Responsive Ad After Question

Answer (115)

Best Answer
(340)
Implement proper error handling (using try-catch blocks). Instead of letting the fatal error crash the application, catch the `mysqli_sql_exception`. Log the error for debugging and provide the user with a friendly error message explaining that there was a problem connecting to the database, rather than displaying a technical stack trace.