Does MySQL know if data has been modified before updating the data?

Source: Internet
Author: User
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.


Reply to discussion (solution)

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.

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.



The data must be there, the statement is correct, and the MySQL return value is problematic.





--Cherish life, stay away from MySQL

So how do I know if my UPDATE statement is really successful,
--Returns true to indicate success.

affect the specific data.
Mysql->affected_rows

Is it possible to add a field that records the modification time so that the number of rows affected is not 0 if no other content is modified?

  • Contact Us

    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

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.