How to get affected rows in a previous MySQL operation?

mysql_affected_rows should get the number of rows affected in a previous MySQL operation, but I want to get the rows affected in a previous MySQL operation. For example:

update mytable set status=2 where column3="a_variable";

Before this operation, the state of some rows is already 2, and I want to get the affected rows in a previous MySQL operation, you cannot get it by issuing a query

select * from mytable where status=2

So how to do this?

+3
source share
2 answers

This can be effectively 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 first query results in strings that will change, and the second query actually modifies them.

, , .

+5

, , PHP, , PHP.

tho, , , SQL , , PHP, , / - ( : , .)

-1

Source: https://habr.com/ru/post/1724261/


All Articles