Determines whether the data has been modified before MySQL updates the data

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

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.