简体   繁体   English

防止在线酒店预订中出现种族状况

[英]prevent race condition in online hotel booking

I asked this question before and people gave me a solution to my problem but now my problem has changes. 我之前问过这个问题,人们给了我一个解决方案,但是现在我的问题有了变化。 Before I had a table called rooms in my database. 在数据库中有了一个名为“房间”的表之前。 It had a hold field where when someone is making a reservation, i put a time 15 mins in the future to keep it for that user. 它有一个hold字段,当有人进行预订时,我会在未来15分钟内保留该用户的时间。 The room becomes available again if that user doesn't finish the reservation in 15 mins. 如果该用户在15分钟内未完成预订,该房间将再次可用。 It was the solution to my previous problem. 这是我以前的问题的解决方案。

But now I no longer have a rooms table. 但是现在我不再有房间表了。 I only have roomtype and reservations table. 我只有房间类型和预订表。 Roomtype got name price info # of rooms and of course id fields. Roomtype获得了房间的名称价格信息#,当然还有ID字段。 The reservations table got checkin checkout roomtypeid and info about the user. 预订表获取了签入结帐的房间类型ID和有关该用户的信息。 Since I don't have the rooms table I can't figure out a way to prevent multiple users from booking a single room at the same time. 由于我没有房间表,因此我无法找出一种方法来防止多个用户同时预订一个房间。

My question is how can I prevent race conditions without the rooms table? 我的问题是如果没有房间桌子,如何防止比赛情况? If it is not too much to ask I would like the solution to be only sql and php. 如果问的不是太多,我希望解决方案仅是sql和php。 Here is a link to my previous question 这是我以前的问题的链接

EDIT: I found this post and that's why I don't have the rooms table anymore. 编辑:我发现了这篇文章,这就是为什么我没有房间表了。 link 链接

you can add a temporary reservation to the reservations table (with a temp-flag/field) and remove that later if the reservation is not finished after 15 minutes. 您可以将临时保留添加到保留表(带有temp-flag / field),如果保留在15分钟后仍未完成,则稍后将其删除。

additionally if multiple users try to reserve the last room very simultaneously you should again check the availability in every step of the reservation to notify users that the last room has just been taken and propose another roomtype etc. 此外,如果有多个用户尝试同时预订最后一个房间,则应在预订的每个步骤中再次检查是否有空,以通知用户刚购买了最后一个房间并提出其他房间类型等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM