If I begin a transaction, and make multiple INSERTs in it (pre-COMMIT), mysql_insert_id() doesn’t seem to update following each one.
Is this the expected behavior? If so, what can I do to get the ID’s for the things I just inserted?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your assumption is wrong. Here is code that proves it:
The output of this simple code is:
The interesting thing is that even if you rollback the transaction (instead of committing it), the result will be the same and the values for these ids will never be used again. So the next insert will start with 4.