What are the best practices for handling database errors and displaying error messages in PHP?

When handling database errors in PHP, it is important to catch exceptions and display meaningful error messages to the user. This can help in troubleshooting and resolving issues quickly. One best practice is to use try-catch blocks to catch exceptions thrown by database operations and then display the error message to the user.

try {
    // Database connection and query execution
} catch (PDOException $e) {
    echo "Database Error: " . $e->getMessage();
}