Re: mySQL query question
| From: | Jim Lucas | Date: | Mon, 17 Nov 2008 06:46:13 +0000 |
| Subject: | Re: mySQL query question | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-283338@lists.php.net to get a copy of this message | ||
Chris wrote:
Jim Lucas wrote:I would agree, but I'm not the OP. He/She wanted it this way...mikesd1@verizon.net wrote:Seems like a perfect candidate for an auto-inc field, though mysql doesn't let you have multiple in the same table (afaik).Ok, so just that I am clear, you are SELECTing and pulling all the data that you are submitting in the above INSERT statement from the DB initially, then you are only modifying the confirm_number value and then re- submitting all the values, as they originally were,Well, actually when all is said and done, a new record will be created with new information (Name, phone, email, etc) and the confirm_number is the previous+1
You do have a race condition, you can end up with 2 of the same confirm_numbers (you'd have to be unlucky, but it can happen). 2 hits at the same time = 2 selects getting the same max(confirm_number), which results in 2 inserts with the same number.Granted that their is a possibility that it could happen. But the chance of it happening with the three statements running back-to-back in the same call is much lower then having three separate calls and doing the math in PHP. -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare