How can errors in PHP database queries be effectively captured and displayed for debugging purposes?

To effectively capture and display errors in PHP database queries for debugging purposes, you can use the try-catch block to catch exceptions thrown by the database connection and query execution. Inside the catch block, you can then display the error message to help identify and resolve the issue.

try {
    // Your database connection code here

    // Your database query code here

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