homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Is mysql_insert_id safe/reliable?

 3:48 pm on Sep 23, 2004 (gmt 0)

I am writing data to a MySQL database. I then immediatly return the ID of that entry to the user using mysql_insert_id:

$query = "INSERT INTO pet VALUES ('id','$petfirst','$petmiddle','$petlast','$petsuffix','$petstreet','$petstreet2','$petapt','$petcity','$petstate','$petzip')";



echo "$ticketid";

Is this safe/reliable if multiple users are on at the same time? Is there a chance that someone may get another users ID?

I was originally was doing the following:

1) write to database,
2) do a new query with some of the variables I entered into the database in step 1 and get the ID from that query

This seemed to be overkill.

thanks for your thoughts.




 3:59 pm on Sep 23, 2004 (gmt 0)

Hey Schoolbag,

This thread may answer your question:


Hope this helps!


 5:17 pm on Sep 24, 2004 (gmt 0)

thank you very much, I searched the forum I swear!

Sorry for the repost.


 3:25 pm on Sep 26, 2004 (gmt 0)

quick trick that the regulars use - search via google using site:webmasterworld.com like this [google.com]. You get much better results than with the site's native search function (the referenced thread is #1 in the search I just gave).


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved