How can error reporting be effectively enabled in PHP to troubleshoot issues like rows not updating in a database?

To effectively enable error reporting in PHP to troubleshoot issues like rows not updating in a database, you can set the error reporting level to include warnings and notices, enable display errors, and log errors to a file for better visibility. This will help you identify any potential issues with your database update queries and pinpoint the root cause of the problem.

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

// Log errors to a file
ini_set('log_errors', 1);
ini_set('error_log', '/path/to/error.log');

// Your database update query
$mysqli = new mysqli("localhost", "username", "password", "database");
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
}

$sql = "UPDATE table_name SET column_name = 'new_value' WHERE condition";
if ($mysqli->query($sql) === TRUE) {
    echo "Record updated successfully";
} else {
    echo "Error updating record: " . $mysqli->error;
}

$mysqli->close();
?>