Page 1 of 1

LAST_INSERT_ID() question

Posted: Thu Aug 16, 2007 11:29 am
by lapith
I was planning to use mysql_insert_id(), and then I read the note stating that it will not work correctly if the ID datatype is BIGINT (which it is in my case). So I at least know that I have to use LAST_INSERT_ID(), however I am a little worried about using this function because I am not sure how it will act with multiple users connecting to the database at the same time. Is it possible that one user using the site will cause a database insert and then before the LAST_INSERT_ID() function call a second user could cause another insert thus throwing the accuracy of the LAST_INSERT_ID() function call? Is it possible that I have to set up some sort of transaction? If I do have to set up a transaction, how do I do so?

Thanks in advance for the help.

Posted: Thu Aug 16, 2007 11:33 am
by feyd
Concurrency issues are always possible.

Posted: Thu Aug 16, 2007 11:45 am
by VladSun
Use InnoDB, not MyISAM storage engine.

Posted: Thu Aug 16, 2007 12:03 pm
by miro_igov
mysqli_insert_id();

Posted: Thu Aug 16, 2007 3:05 pm
by thinsoldier
VladSun wrote:Use InnoDB, not MyISAM storage engine.
I've always wondered whether it was ok to use one of the other engines. Why do [s]u[/s] you suggest InnoDB? What are it's benefits? Is it your favorite?
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.

Posted: Thu Aug 16, 2007 4:51 pm
by VladSun

Posted: Fri Aug 17, 2007 3:38 am
by miro_igov
Is it not much easy to keep your current database and just use the mysqli extension which does not have issues with getting the last insert id on bigint fields?

Posted: Sat Aug 18, 2007 8:20 pm
by volka
lapith wrote:Is it possible that one user using the site will cause a database insert and then before the LAST_INSERT_ID() function call a second user could cause another insert thus throwing the accuracy of the LAST_INSERT_ID() function call?
No, LAST_INSERT_ID() works per connection.