防止两个用户在php中获取相同的值[关闭]

可以说我有这张桌子:

|  id |   fruit   |   status 
--------------------------------
|   1 |   banana  |   good
|   2 |   apple   |   good   

User send request to server -> server send a response with the fruit -> server updated status to 'consumed'

Imagine the following scenario in which two users send a request at the same time saying that they will consume a fruit that has good status

How to prevent both users from having a 'banana' answer?

评论