What are the best practices for handling MySQL errors in PHP to improve debugging and error resolution?

When handling MySQL errors in PHP, it is important to properly catch and display the error messages to aid in debugging and error resolution. One way to do this is by using try-catch blocks to catch exceptions thrown by MySQL queries and then displaying the error message. Additionally, using error reporting functions like mysqli_error() can help provide more detailed information about the error.

try {
    // MySQL connection code

    // MySQL query code

} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}