[nycphp-talk] MySQL concurrency 101
David Mintz
dmintz at davidmintz.org
Thu Dec 11 12:46:24 EST 2003
On Thu, 11 Dec 2003, David Sklar wrote:
> On Thursday, December 11, 2003 12:13 PM, wrote:
>
> > Basic question. What is/are the recommended strategies for dealing
> > with the lost update problem in a PHP/MySQL application? <snip />
> 1. Include a "last_update" column in the table. This can be a timestamp or
> just a monotonically increasing integer that changes with each update.
>
> 2. When you read the record and display the form, include the last_update
> value as a hidden field in the form.*
>
> 3. When the form is submitted, check to see that the last_update value
> submitted with the form is the same as the value in the database before
> updating.**
>
> 4. If the values don't match, take some application-appropriate behavior,
> like silently overwriting with the new data; re-presenting the form to the
> user with fields highlighted that have changed; etc.
>
> 5. If the values do match, then save the data, including a new value for the
> last_update column.
<snip />
I thank you sir. This sounds sound. I read/heard about this technique
someplace before but I think I was thinking, yeah but what if two users
SELECT the same data simultaneously. Answer: not your problem. If they
both try to write one of them will just have to suffer a little
inconvenience, for data integrity's sake.
---
David Mintz
http://davidmintz.org/
"Anybody else got a problem with Webistics?" -- Sopranos 24:17
More information about the talk
mailing list