mysql_affected_rows is to get number of affected rows in previous MySQL operation, but I want to get affected rows in previous MySQL operation. For example:
update mytable set status=2 where column3="a_variable";
Before this operation, status of some rows is already 2, and I want to get affected rows in previous MySQL operation, you can not get it by issuing a query of
select * from mytable where status=2
So how to do this work?
It can be efficiently and simply achieved with the following:
select * from mytable where column3="a_variable" and status != 2;
update mytable set status=2 where column3="a_variable";
The result of the first query are the rows that are going to change, and the second query actually changes them.
If this is a high performance system, you may need to take special care with transactions to prevent a new row slipping in between those 2 queries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With