Re: [PHP] database abstraction layer

[email protected] (Ashley Sheridan)
Newsgroups php.general
Message-ID <1265153704.2261.271.camel@localhost>
On Wed, 2010-02-03 at 00:31 +0100, Rene Veerman wrote:

> On Wed, Feb 3, 2010 at 12:18 AM, Ashley Sheridan
> <[email protected]>wrote:
> 
> >  The problem is where 2 people choose the same instant to perform an
> > action on your site that inserts a record into your db. The db engine
> > inserts them one after the other, and then responds about the max(id) to
> > your PHP script. Then, you now have 2 people who have the same max(id)
> > retrieved, but one of the values is wrong.
> >
> 
> well, i only use getmaxid()s for inserts.
> the timelag between getmaxid() and the insert is so small it'd take 300-800
> insert-requests/sec
> (on that particular table) before an error condition would arise.
> in which case, a tested piece of sql would fail, and can be routed through
> the retry functions .
> These would imo provide ample timing re-randomization, aswell as a measure
> of stress-relief for both php and mysql server.
> You may correct me if i'm wrong :)
> 
> BTW: php core developers: can we have a sleep() that accepts a float? :)


It's the reason transactions exist, to prevent things happening like
this. When you have two actions where one is dependent on the other,
unless you have a way to tie them together so that they can't be broken,
you run the risk of collisions.

Thanks,
Ash
http://www.ashleysheridan.co.uk
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.