I found some related readings on AUTO_INCREMENT on the net and wanted to ask you guys a few things.
Here’s a bit of code that I found related to AUTO_INCREMENT inserting. I was not sure if the field is auto_increment if I should skip it in PDO syntax when inserting, or mention it and set it NULL, because it will AUTO_INCREMENT anyways.
INSERT INTO CUSTOMER_ADDRESS (ADD_ID, ADD_TEXT) VALUES(NULL, 'some address value');
INSERT INTO CUSTOMER_DETAILS (NAME, ADD_ID, GENDER, PHONE_NO)
VALUES ('James Bond', LAST_INSERT_ID(), 'MALE', 007);
Now, my question is :
- LAST_INSERT_ID() or PDO’s PDO::lastInsertID ($dbh->lastInsertId();) is really the last AUTO_INCREMENT id that i’ve done, or is it the last AUTO_INCREMENT that the server has done ? (keeping in mind that when I call the function, another say 50 inserts have already completed, and the lastInsertID is now different…..so is it my last insert or the server’s last insert.
Thanks a lot,
really appreciate your knowledge
LAST_INSERT_ID()is connection specific, not server specific.Hence it’ll always relate to the last insert you did.