in Thinkphp's curd, a strange problem arises when using the Save method, that is, if the data is not updated (same as the original data), the return value is judged to be false. It was a long time ago that the problem was discovered, once thought to be an official code problem, but it has been delayed until recently to solve the problem. I have to say, "Tomorrow will be a day, so much tomorrow." Everything to-morrow, everything is wasted. ", with June Mutual encouragement! after searching for the problem on the official website, it was found that the authorities had solved the problem, the original judgment:
$result = $Model->where (' id=1 ')->save ($data), if ($result) { echo ' success ';} Else{ echo ' false ';}
Workaround: Use "= = =" To determine the return value
$result = $Model->where (' id=1 ')->save ($data), if ($result!== false) { echo ' success ';} Else{ echo ' false ';}
Problem solved, but still did not understand the reason, so went to see the Save method to implement the source code (3.2.3 version MySQL driver):
The bottom of the model in TP is encapsulated by the PDO class, so continue looking for the rowcount method in PDO:
The reason is found, because the data is not changed, so the number of bars affected by the data is zero, the return value is 0, and 0 in the PHP judgment is false, so there is the above situation. When using "= = =" Judgment, because the variable type is judged, 0 and false are not equal, the problem is solved.
thinkphp if data is not modified when data is updated, the result is wrong to be returned