MySQL Forums
Forum List  »  PHP

How to lock and update data between two table in mysql
Posted by: david lin
Date: March 31, 2006 11:56PM

Hi,

I have two mysql tables which are user and gift.
I will to do these processes in my program:
----------
mysql_query("SELECT user_points FROM users where userid='peter' FOR UPDATE");
mysql_query("SELECT gift_number, gift_points FROM gifts where product='xbox' FOR UPDATE");

if($gift_number > 0 && $gift_points > $user_points)
{
mysql_query("UPDATE user SET user_points=user_points-$gift_points WHERE userid='peter'");
mysql_query("UPDATE gifts SET gift_number=gift_number-1 WHERE product='xbox'");
**Problem 1** Is the procedure right or wrong?
**Problem 2** How to unlock these tables?
} else {
**Problem 3** How to unlock theses two tables in the else condition ? Does anyone know?
}
------------------
Thank you very much.

Options: ReplyQuote


Subject
Written By
Posted
How to lock and update data between two table in mysql
March 31, 2006 11:56PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.