Before MySQL updates data, determine whether the data has been modified. execute an update statement in MySql {MyPhpAdmin:
Update tableA set a = 1 where id = 2
If the original value of a is 1, MySql returns "0 rows affected ".
If the original value of a is not 1, "1 line affected" is returned ";
Is it true that MySql still compares the new value with the old value before executing the update statement. if it is modified, it will be modified. if it is not modified, will it not execute the update statement?
In PHP
If you execute the mysql-> query (); statement, if the statement itself has no errors, return true directly. I execute update. if the syntax is correct and the condition is incorrect, query returns true directly.
If you use mysql-> affected_rows to determine whether the statement is correct, the condition is correct, that is, no data is modified, and 0 rows are returned. In this way, how can I know that my update statement is successfully executed and affects the specific data.
Reply to discussion (solution)
It's tangled ..
You must know whether the statement is correct, whether the data exists, and whether it is modified after update.
I think it is necessary to select one to meet all your needs.
It's tangled ..
You must know whether the statement is correct, whether the data exists, and whether it is modified after update.
I think it is necessary to select one to meet all your needs.
The data must exist, the statement must be correct, and there is a problem in commenting on the MySql return value.
-- Cherish life and stay away from MySql
In this way, how can I know that my update statement is successfully executed,
-- If true is returned, the operation is successful.
Affects specific data.
Mysql-> affected_rows
Can I add a field for the record modification time so that the number of rows affected is not 0 if no other content is modified?