Hi...
I am not exactly sure what you mean by booking, so I assume it is a paid reservation:
beyondidiocy wrote:Two: View locking
Now this might get complicated ...
This is your only option. Yes it does get complicated; in fact it should have been designed in from the beginning. It is also very difficult to test, so you need to secure it by static analysis alone. Hope you have a clear head

. Here are two approaches...
I assume that booking a room is a multipage process, so the first way is to cope with this as best we can. You cannot easily use database transactions over mutli page requests (called long transactions). It is technically difficult within PHP and is a bad idea anyway as you will bring the database server to it's knees. This means that you must implement two levels of locking.
When a buyer starts booking a room you first check that noone else is booking the room and if clear you attach the buyer to a room. The booking process cannot start without this condition. This
must be transactional. For example...
class Booking {
...
function confirm(&$room) {
$this->_connection->begin();
if ($room->isBooked()) {
$this->_connection->rollback();
return false;
}
$room->book($this);
return $this->_connection->commit();
}
}
Now the room will be correctly held until the booking process is complete. The trouble is that if the process is abandoned the room will be locked forever. This means that you have to have a timeout within the booking object so that it can go stale after inactivity. This in turn means that each stage of the booking process must carry out a transactional check that it hasn't dropped out.
The second approach is simpler overall. That is to get the booking process onto a single page. The way to do this is for the software to do less. This may seems strange, after all we are in the business of automation, but in fact deciding what to code is a careful balancing act. By pushing the problem back out into the domain you often find that systems already exist to deal with the complexity.
I suspect that the hotel business already has rules for reservations as well as paid for bookings. They manage to cope with double bookings already right? How?. You need to ask them what their system is.
For example by splitting off reservation from paid booking you can probably get each down to a single web page. Once you do that you can use database transactions to make a room booking atomic, rather than simulating long transactions. The concept of reservation will have to be visible, as well as accompanying text explainig how it works, but the hotellier will get much more flexibility in how the system is managed. They could introduce first and second choices for example (unlikely, but you see what I mean).
Hope this helps.
Hm. I am thinking more and more these days that the concept of transactions already exists in the business world and that we as developers should make use of that knowledge...
yours, Marcus