How can SQL query errors be debugged effectively in PHP scripts?

To debug SQL query errors in PHP scripts, you can use the `mysqli_error()` function to get detailed error messages from the database server. By echoing or logging these error messages, you can identify the issue in your SQL query and make necessary adjustments to fix it.

// Perform the SQL query
$result = mysqli_query($conn, "SELECT * FROM users WHERE id = 1");

// Check for errors
if (!$result) {
    echo "Error: " . mysqli_error($conn);
} else {
    // Process the query result
    while ($row = mysqli_fetch_assoc($result)) {
        // Do something with the data
    }
}

// Close the connection
mysqli_close($conn);