If you need to know specifically whether the WHERE condition of an UPDATE operation failed to match rows, or that simply no rows required updating you need to instead check mysqli::$info.
As this returns a string that requires parsing, you can use the following to convert the results into an associative array.
Object oriented style:
<?php
preg_match_all ('/(\S[^:]+): (\d+)/', $mysqli->info, $matches);
$info = array_combine ($matches[1], $matches[2]);
?>
Procedural style:
<?php
preg_match_all ('/(\S[^:]+): (\d+)/', mysqli_info ($link), $matches);
$info = array_combine ($matches[1], $matches[2]);
?>
You can then use the array to test for the different conditions
<?php
if ($info ['Rows matched'] == 0) {
echo "This operation did not match any rows.\n";
} elseif ($info ['Changed'] == 0) {
echo "This operation matched rows, but none required updating.\n";
}
if ($info ['Changed'] < $info ['Rows matched']) {
echo ($info ['Rows matched'] - $info ['Changed'])." rows matched but were not changed.\n";
}
?>
This approach can be used with any query that mysqli::$info supports (INSERT INTO, LOAD DATA, ALTER TABLE, and UPDATE), for other any queries it returns an empty array.
For any UPDATE operation the array returned will have the following elements:
Array
(
[Rows matched] => 1
[Changed] => 0
[Warnings] => 0
)