Welcome to WebmasterWorld Guest from 50.19.190.144

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Is mysql_insert_id safe/reliable?

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

Junior Member

10+ Year Member

joined:Jan 19, 2003
posts:63
votes: 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')";

mysql_query($query);

$ticketid=mysql_insert_id();

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.

Fred

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

Junior Member

10+ Year Member

joined:Feb 29, 2004
posts:194
votes: 0


Hey Schoolbag,

This thread may answer your question:

[webmasterworld.com...]

Hope this helps!

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

Junior Member

10+ Year Member

joined:Jan 19, 2003
posts:63
votes: 0


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

Sorry for the repost.

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

Moderator

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 25, 2002
posts:8139
votes: 103


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).

Tom