Re: Help with logic :(

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Richard Lynch wrote:
On Mon, October 10, 2005 3:24 pm, Dan McCullough wrote:

create a function to check if the rndnumber=couponcode row count = 0
if not then redo rndnumber if it does = 0 then insert rndnumber


Noooooooooooooooooooooooooooo!

You are creating a RACE CONDITION in which ONE user might generate a
'valid' code, and ANOTHER user might generate a 'valid' code AT THE
SAME TIME, and then they BOTH get the same coupon code.

The probability of this is very very very low, but still NOT zero.

And it's the kind of thing that won't show up in testing, but sure as
God made little green apples, it WILL happen at the worst possible
time after you "go live"

lol. Richard you should write a book :-) (or should that be 'another book'?)


The database engine has a *TON* of code in it to avoid this kind of
Bad Thing happening.

Use it.

create a UNIQUE INDEX on the column that needs to be unique.

Trap the INSERT error.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux