How does lastInsertId() work for tables that do not have an auto-incremented field? What about tables where the primary key is made up of 2 fields?
(I’m working with MySQL)
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.
In both cases above it will return
0.When using an auto_increment column, it will return the last INSERT ID even if it was specified (i.e. the auto increment was not used).
That is to say you should only use
lastInsertIdwhen using auto increment. It doesn’t really make sense to use it otherwise since you would have to know the keys ahead of time anyway..