How to get the number rows that has been actually changed


When running an update query, if new values are the same as the old ones, mysql returns 0 for the affected_rows. But sometimes we need to know whether our update query actually changed any row or not.

there is a way to know that, a bit awkward but still.

$info = "Rows matched: 40 Changed: 40 Warnings: 0";
preg_match("!Rows matched: (\d+) Changed: (\d+) Warnings: (\d+)!", $info, $matches);
var_dump($matches);

Related articles: