table locking

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
nickthorley
Forum Newbie
Posts: 1
Joined: Thu Aug 05, 2004 4:10 am

table locking

Post by nickthorley »

Hi all

I am new and learning php - I know all of the basics but wanted to ask about table locking. I was thinking how a say warehouse app would be written if it was done in php.
I know record locking can be done but not sure how it works in reality. Say I am the first person to ask for stock - lets say that the transaction takes a while and a second person wants stock. Now does their script have to wait - (appears to be taking a long time to load to the user) until the unlock. Or does the script accept the request straight away and the database queues the request?. If it is the later then how does the user know what has happened. Technically if the first person has had the last of the stock then the second person should be told storry no stock (they would be if they had to hold waiting) However if the transaction was accepted and queued then the second person would assume that they have got stock when they havent.

Can anyone advise please
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

There are various ways. One is to use some of the mysql internal functions to see if there is a lock set. If so, notify the user that something is happening, please retry or whatever.

There is also the possability to use the shopping-cart system. Once you press the "order me" button, the amount of order is moved into a temporary storage ($_SESSOINs or temp-table). The customer later need to verify the cart's content, and during that a check against pre-ordered articles and the stock could be matched. If one item suddenly is 0 in stock, a brief message could occur.

I personally only have made the shopping-cart version, but for those companies, the stock is (for what I know) is never close to being sold out...
Post Reply