Suggestion To Avoid Two User Book A Same Things At Same Time For Booking System

Hi,

i now doing the booking system and i facing some difficulties.How to prevent two user booking the same place same time?I think to use session expired but still hope that anyone can give some other suggestion to avoid this problem.Thanks.

I think the problem of two people making the same reservation at the same millisecond is too rare of a situation that you don’t need to worry about it.

So how ever you are checking if a unit/time is already booked should work just fine, i.e. first come first served.

I would look into a custom validation rule for this.

You have to use a database which support row level locking.

In case of mysql … Use InnoDB database engine.

Obtain the place model as below :




Yii::app()->db->beginTransaction();

Place::model()->findBySql(

                    "SELECT * FROM ". Place::model()->tableName. " WHERE pk=:PK LIMIT 1 FOR UPDATE", array(':PK' => place_id);


.. Do booking here.


Yii::app()->db->currentTransaction->commit();