I have decided to implement the "soft-lock" schema below.  I cannot use the
userID as the value for the lock.  Is there any other unique number that can
be generated that I could use.  I am thinking about using a session_ID in
PHP?  Any suggestions/Comments??

Randy

-----Original Message-----
From: Cal Evans [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 24, 2001 4:10 PM
To: Randy Johnson; [EMAIL PROTECTED]
Subject: RE: Doing multiple updates


Randy,

My recommendation (and there are probably many people who will disagree with
me) is to use a "soft-lock" schema.

In your account table, add a field named lockedBy. I usually add a field
named lockedAt also as a timestamp.

the basic flow is this:

1: Check to see if the record has something in lockedBy
-NO-
2: Update the record with your userID
3: Check to see if there record has something in lockedBy and it is you.
-YES-
4: you have successfully soft-locked the record for update. Go ahead and
make your update
5: update the record to remove the lock.

WARNING: This system assumes that you have control over all processes that
access the database.  If there is a chance that someone will come in and be
able to modify the data outside of your code then they can bypass your
checks and modify the data.

In many DBMSs (not sure yet about MySQL) record locks keep people for even
seeing the data and some (M$ SQL) used to lock whole tables to do a single
update. (sux big time)

HTH,
Cal
http://www.calevans.com


-----Original Message-----
From: Randy Johnson [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 24, 2001 2: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

Reply via email to