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