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:
- Mysqli tutorial (how to use it properly)
- How to connect properly using mysqli
- How to report errors in mysqli
- How to check whether a value exists in a database using mysqli prepared statements
- Mysqli helper function
- Why mysqli prepared statemens are so hard to use?
- Authenticating a user using mysqli and password_verify()
- Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given.
- Mysqli examples
- Mysqli's features you probably would like to know about
- How to run INSERT query using Mysqli
- How to use mysqli properly
Add a comment
Please refrain from sending spam or advertising of any sort.
Messages with hyperlinks will be pending for moderator's review.
Markdown is now supported:
>
before and an empty line after for a quote