thinkphp determine if the modification was successful

Source: Internet
Author: User
Tags mysql command line

Use the Save method in thinkphp to update the data
The normal execution of the Save method returns a value that is affected by the number of records, returns false On error, returns 0, and returns false in many business scenarios that are different.

And when the modified content and the original content of the same time returned is 0, usually in the modified content of the form without any modification click the Modify button is the case.
0 and false are different, although they represent false when they are Boolean. 0 means that the modification is unmodified without executing the error, and false means that an error occurred while executing.
Therefore, when judging whether the modification is successful, you cannot use the if (....->...->save ()) as a condition of judgment, and should use the IF (...->...->save ()!==false) as a condition to determine if the update is performed or not, Also determine if the value and type match false.

The following is an example of the MySQL command line cited:

To create a new table:

MySQL>createtableint0 rows affected (0.85 sec)

Insert Bar Data:

MySQL>insert into t (ID)values(21 Row affected ( 0.24 sec)

Make an UPDATE statement that does not change the data:

MySQL>updateset id=2where id=2   0 rows affected (0.131  0  0

Note that changed is 0, stating that the content has not been modified. The UPDATE statement is executed normally, which corresponds to the time that Save () returns 0.

Execute an UPDATE statement that changes the data:

MySQL>updateset id=3where id=2   1 row affected (0.141  1  0

Changed is 1, indicating that the UPDATE statement modified the content. Corresponds to the time of Save () >0.

Then execute an error UPDATE statement:

MySQL>updateset id=2where ida=3   1054column'ida'in'where Clause'

An error occurred, corresponding to the time that Save () is false.

thinkphp determine if the modification was successful

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.