control structure for a falied MySQL query?
Hello all -
I have an SQL statement that generates a random code number. In the
table definition, the code number has a unique index, so my concern is
that the randomly-generated number could fail the UNIQUE constraint.
What PHP control structure can I use to keep re-trying a query until
it doesn't fail? Most of the time it will successfully insert, and my
guess is that it will only need a second try to generate an unused
number. But, I would like to have bullet-proof code to keep trying the
statement until it doesn't fail.
How could I do this? Here is my sql statement:
INSERT INTO Cards ( code_number ) VALUES ( LPAD( FLOOR( RAND() *
100000 ), 5, '0' ) )
|