I had a weird problem, our website has registration form coded using zend form, I have checked database either username existed or not before zend db insert operation, it is working fine always, also worked fine for our thousands of the users, but just few (about 100) records has duplicates stored automatically(guessing) even in 10 or 20sec seconds difference there is no possibility of form submission again with different values except auto increment column.
The situation is pretty simple and called "racing".
1. User1 submit form (email: x@x.com) 2. User2 submit form (email: x@x.com) 3. verify no x@x.com for User1 4. verify no x@x.com for User2 - before nither of them added there is no x@x.com in DB 5. Add to db User1 6. Add to db User2 - you have got an duplication error.
Solution:
1. unique index to filed email 2. transaction (started from verification email exist up to insert a new record)