Can somebody provide me with some sample code for the following. I read it
over in the manual but am still lost.
thanks
Randy
+++++++++++
Sounds like you want a mutex and you can use get_lock and release_lock in
mysql for that.
http://www.mysql.com/doc/M/i/Miscellaneous_functions.html
GET_LOCK(str,timeout)
Tries to obtain a lock with a name given by the string str, with a timeout
of timeout seconds. Returns 1 if the lock was obtained successfully, 0 if
the attempt timed out, or NULL if an error occurred (such as running out of
memory or the thread was killed with mysqladmin kill). A lock is released
when you execute RELEASE_LOCK(), execute a new GET_LOCK(), or the thread
terminates. This function can be used to implement application locks or to
simulate record locks. It blocks requests by other clients for locks with
the same name; clients that agree on a given lock string name can use the
string to perform cooperative advisory locking:
mysql> select GET_LOCK("lock1",10);
-> 1
mysql> select GET_LOCK("lock2",10);
-> 1
mysql> select RELEASE_LOCK("lock2");
-> 1
mysql> select RELEASE_LOCK("lock1");
-> NULL
Note that the second RELEASE_LOCK() call returns NULL because the lock
"lock1" was automatically released by the second GET_LOCK() call.
RELEASE_LOCK(str)
Releases the lock named by the string str that was obtained with GET_LOCK().
Returns 1 if the lock was released, 0 if the lock wasn't locked by this
thread (in which case the lock is not released), and NULL if the named lock
didn't exist. The lock will not exist if it was never obtained by a call to
GET_LOCK() or if it already has been released.
Mark.
-----Original Message-----
From: Randy Johnson [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 24, 2001 8:48 PM
To: [EMAIL PROTECTED]
Subject: Doing multiple updates
Hello,
I am creating a mock site that has a money balance that people can login
and pretend to pay money for stuff online via my site.
I am using php with mysql to implement this.
How do I make sure that a balance for a particular account is (locked) so
only 1 spend for that account can happen at one time?
for example my php script grabs the balance from the payer account and
receiver account. How do I make sure that the balance is locked so the
balance is read before the updated transaction occurs causing the person to
spend money that he/she doesn't have.
I hope I have provided enough explanation for you guys to point me in the
right direction.
thanks
randy
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail
<[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php