How can error reporting be effectively utilized in PHP to troubleshoot issues with database updates and ensure data integrity?

When updating a database in PHP, it is important to utilize error reporting to troubleshoot any issues that may arise and ensure data integrity. By enabling error reporting and checking for errors after executing database queries, developers can quickly identify and resolve any issues that may occur during the update process.

// Enable error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Execute database update query
$query = "UPDATE table_name SET column_name = 'new_value' WHERE condition";
$result = mysqli_query($connection, $query);

// Check for errors
if(!$result) {
    echo "Error: " . mysqli_error($connection);
} else {
    echo "Database update successful";
}