NYCPHP Meetup

NYPHP.org

[nycphp-talk] MySQL concurrency 101

Cogswell, Eric eric.cogswell at innlink.com
Thu Dec 11 12:42:22 EST 2003


I ran into the same problem not too long ago.  Solved it by sending in
the "old" field values along with the actual form values entered by the
user.

<input type="text" name="homephone" value="<?=$home_phone;?>">
<input type="hidden" name="old_homephone" value="<?=$home_phone;?>">

<input type="text" name="workphone" value="<?=$work_phone;?>">
<input type="hidden" name="old_workphone" value="<?=$work_phone;?>">

And so on.  Then, when you receive the form, check the user-entered
value against the "old" value.  If they are different, then save the new
value to the db, otherwise don't touch it.  Basically, you only update
the information that was changed by the user.  If user1 updates the home
phone number and user2 updates the work phone number, their repsective
data will not be overwritten by the other because it wasn't changed on
their form.  It seems to be working pretty well for me so far.

-Eric

-----Original Message-----
From: David Mintz [mailto:dmintz at davidmintz.org] 
Sent: Thursday, December 11, 2003 11:13 AM
To: NYPHP Talk
Subject: [nycphp-talk] MySQL concurrency 101




Basic question. What is/are the recommended strategies for dealing with
the lost update problem in a PHP/MySQL application? The scenario I'm
thinking of is not the old shirt inventory example which can be solved
with relative as opposed to absolute updates. I'm thinking:  User1
requests a page containing a form populated by a row of John Customer's
data from a table; so does User2. User1 updates John Customer's work
phone in the form and User2 updates John Customer's home phone. User1
submits form/updates table, then User2 does likewise, overwriting
User1's update.

I've done considerable RTFM and I'm conversant with locks, transactions,
etc. I'm uncertain about how to put it all together in a web app, i.e.,
with lots of short-lived independent scripts running in a stateless
environment.

The possible approaches I can think of are a little cumbersome -- I'll
spare you, for the sake of brevity.

Any pointers to tutorials, articles etc are appreciated. Thanks.


---
David Mintz
http://davidmintz.org/

        "Anybody else got a problem with Webistics?" -- Sopranos 24:17
_______________________________________________
talk mailing list
talk at lists.nyphp.org http://lists.nyphp.org/mailman/listinfo/talk



More information about the talk mailing list