Transaction and locking?
Posted: Wed Jun 20, 2007 7:23 am
Hi,
I am new to PHP and have an e-commerce project with a shopping cart functionality. I'v developed the "add","delete","update" functions of the shopping cart but have some problems with "place order".
My database is MySQL 5.0.37
Here are relative tables about order placement:
"Inventory" - store my all products (products include: A,B,C,...I,J,K)
"Orders" - store order information (order ID, buyer ID,...etc.)
"Order_detail" - store order details (product ID, unit price, quantity,...etc.)
My scenario is :
3 persons check out the shopping cart at the same time,
person 1 buy products A,B,C,D,E,F,G
person 2 buy products C,D,E,F,G,H,I
person 3 buy products E,F,G,H,I,J,K
In the scenario, should I lock the whole 3 table or simply lock the related rows when I create a new order to prevent error?
Since I have no idea how to use transaction or locking properly, the other way on my mind is to set a "time flag". When the first person click the "check out" button, set the flag to "hold on" and call a counter to countdown 1 minute to process the order to prevent the other two persons doing the same thing.
Which way is better? How to do?
I'v read the book "Beginning PHP 5 and MySQL E-Commerce from Novice to Professional" but the book mentioned few about this part. Could anyone recommend me some books mentioned about it?
Many thanks!
I am new to PHP and have an e-commerce project with a shopping cart functionality. I'v developed the "add","delete","update" functions of the shopping cart but have some problems with "place order".
My database is MySQL 5.0.37
Here are relative tables about order placement:
"Inventory" - store my all products (products include: A,B,C,...I,J,K)
"Orders" - store order information (order ID, buyer ID,...etc.)
"Order_detail" - store order details (product ID, unit price, quantity,...etc.)
My scenario is :
3 persons check out the shopping cart at the same time,
person 1 buy products A,B,C,D,E,F,G
person 2 buy products C,D,E,F,G,H,I
person 3 buy products E,F,G,H,I,J,K
In the scenario, should I lock the whole 3 table or simply lock the related rows when I create a new order to prevent error?
Since I have no idea how to use transaction or locking properly, the other way on my mind is to set a "time flag". When the first person click the "check out" button, set the flag to "hold on" and call a counter to countdown 1 minute to process the order to prevent the other two persons doing the same thing.
Which way is better? How to do?
I'v read the book "Beginning PHP 5 and MySQL E-Commerce from Novice to Professional" but the book mentioned few about this part. Could anyone recommend me some books mentioned about it?
Many thanks!