PHP / MySQL - how to prevent two requests *Update

前端 未结 5 1325
清酒与你
清酒与你 2020-12-23 22:02

I have some question ... example: a user will buy something for his USD

  1. Check his USD Balance
  2. Deduct the USD from his account
  3. Make an Order -
5条回答
  •  不思量自难忘°
    2020-12-23 22:22

    First off, you have to use transactions, but that's not enough. In your transaction, you can use SELECT FOR UPDATE.

    It's basically saying, "I'm going to update the records I'm selecting", so it's setting the same locks that an UPDATE would set. But remember this has to happen inside a transaction with autocommit turned off.

提交回复
热议问题