I have a problem on my website. It turns out that I have a packs table which has a availability column. A pack will be available as long as the availability is > 0 . A user can reserve an available pack, upon payment with Stripe.
This form will make an INSERT in the database in the reservations table, checking before there are available packs .
When doing an INSERT I have a trigger that performs an UPDATE on the packs table by subtracting the < strong> availability in 1 unit.
However, when booking a pack, if you enter N requests at the same time, N INSERT , these will trigger N UPDATES and availability will end up being -N values. As many as reservations have entered at the same time.
The question is: How can I avoid an INSERT being done concurrently? That is to say, when a petition arrives, do not enter any more.
I am interested in doing it for PHP code since I want to avoid that the payment is made by the client in case the availability of the pack is 0. p>
Thank you.