MySQL update data header to determine whether the data has been modified
Source: Internet
Author: User
Does MySQL know if data has been modified before updating the data?
An UPDATE statement is executed in Mysql{myphpadmin}:
Update TableA set a=1 where id=2
If the original value of a is 1,mysql, it returns "affects 0 rows" directly.
If the original value of a does not 1, it will return "affects 1 rows";
Does MySQL still compare the new value and the old value before executing the UPDATE statement, and if there are any modifications to modify it, do not execute the UPDATE statement?
There's PHP inside.
Executes Mysql->query (); If the statement itself does not have an error, it returns true directly. I perform update, and if the syntax is correct, the condition is wrong, and query returns true directly.
If you judge with Mysql->affected_rows, there will be a problem in the above MySQL: The statement is correct, the condition is correct, is not modified data, return 0 rows. So how do I know that my update statement really succeeds, affecting the specific data.
------to solve the idea----------------------
Look on the tangled.
You must know whether the statement is correct, whether the data exists, and whether it was modified after the update.
I think I need a select to meet all your needs.
------to solve the idea----------------------
So how do I know if my UPDATE statement is really successful,
--Returns true to indicate success.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service