On Mon, Feb 9, 2009 at 9:25 AM, tedd <tedd.sperl...@gmail.com> wrote: > At 9:00 AM +1100 2/9/09, Chris wrote: >> >> Person a signs up with em...@example.com >> >> Before you are able to fetch the result (which is possible in a high >> traffic site), person b also signs up with em...@example.com >> >> Going back to person a, when you fetch, you get record #2 instead of #1. >> >> They are not the same record. >> >> Not a great example because you probably wouldn't have people using the >> same address from different locations, but it's just to demonstrate the >> problem of doing it this way. > > That's not true, or at least I don't believe it.
Well, that's your prerogative. :-) > If I have a script that has opened and established a communication link with > a dB and has just created a new record with an unique email address and the > code immediately (next few lines in the script) follows that action with > asking the dB to pull the record just created with that email address, then > I AM getting the same record regardless -- there are no RACE conditions > here. Yes, there could be race conditions. The race condition won't come from within the same request, but unless you have *defined* a UNIQUE INDEX/CONSTRAINT on the column as Chris suggested, it is possible (however unlikely you believe it is) for another request to come in at nearly the same time (either another user or someone who manages to double-submit your form, say, by double-clicking the button) with the same value. In that case, each request will execute an insert into the database, and it's anyone's guess which record(s) they will get when they try to select it back out. The unique index/constraint will prevent this as it will only allow one of those records in. The other will fail. > Keep in mind that I AM using unique identifiers, such as a logon/password or > email address. If I create a record using that unique identifier and then > ask the dB to deliver it, then it is without doubt the same record. > > If I was not using an unique identifier, then I would agree with you. But > unique is unique -- it makes no difference if it's a record ID or email > address -- both are unique. You are right, but the point is that if you intend something to be unique then you should declare it as such in the database. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php