Get number of rows matched by UPDATE query with PHP mysqli

I used the following code:

// Parse the digits from the info string that has the following format:
// Rows matched: 0 Changed: 0 Warnings: 0
preg_match_all('!\d+!', $mysqli->info, $m);
return $m[0][0]; 

it's in the options of mysqli_real_connect.

Also introduced in PDO::MySQL in PHP 5.3.


You could run SELECT COUNT(*) with the same WHERE clause before running the UPDATE. That will give you a count of the number of rows that would be matched.