سؤال

From what I have read LAST_INSERT_ID() retrieves the id of the last insert statement to run. If that the last insert statement run on your connection or the last insert run on the database for all connections? I guess what I am trying to ask is: on a busy database driven website what are the chances the following code would return the wrong id, and is there a method to prevent that other then locking the database?

INSERT INTO example (string) VALUE ('something');
SELECT LAST_INSERT_ID();

Would PHP's mysql_insert_id() be a better solution, or should I just query for data that was just inserted and grab id that way?

لا يوجد حل صحيح

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top