Welcome to WebmasterWorld Guest from 50.17.74.162

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Is mysql_insert_id safe/reliable?

     

Schoolbag

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

10+ Year Member



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

jusdrum

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

10+ Year Member



Hey Schoolbag,

This thread may answer your question:

[webmasterworld.com...]

Hope this helps!

Schoolbag

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

10+ Year Member



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

Sorry for the repost.

ergophobe

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

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



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