If no data is modified when thinkphp updates the data, an error is returned. thinkphp returns
In the CURD of thinkphp, a strange problem occurs when the save method is used, that is, if the data is not updated (the same as the original data), the return value is false. In fact, this problem was discovered a long time ago. I thought it was a problem with the official code, but it had been delayed until recently before I thought it was necessary to solve this problem. I have to say, "Tomorrow, tomorrow, how many things are there tomorrow. Everything is waiting for tomorrow, and everything is always ready .", Share with you! After searching for the problem on the official website, I found that the problem has been solved by the official website. The original judgment was as follows:
$ Result = $ Model-> where ('Id = 1')-> save ($ data); if ($ result) {echo 'success ';} else {echo 'false ';}
Solution: Use "=" to determine the return value.
$ Result = $ Model-> where ('Id = 1')-> save ($ data); if ($ result! = False) {echo 'success';} else {echo 'false ';}
The problem was solved, but I still did not understand the cause. So I checked the source code of the save method (mysql driver 3.2.3 ):
The underlying layer of the model in Tp is encapsulated by the pdo class, so we can continue to look for the rowCount method in the pdo:
The cause is found. Because the data has not changed, the number of affected items in the data is zero, and the return value is 0, while 0 is false in php judgment, so the above situation occurs. When "=" is used to determine the type of the variable, the values 0 and false are not equal. The problem is solved.