By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,987 Members | 1,592 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,987 IT Pros & Developers. It's quick & easy.

is mysql_insert_id safe

P: n/a
Hi all

With regard to mysql's mysql_insert_id function is it possible that the
query can return the insert id from another insert performed by a
another user of the database which occured after the initial insert by
the first user but b4 the insert_id part can be queried.
Regards

Marc

Jun 13 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Rik
monomaniac21 wrote:
Hi all

With regard to mysql's mysql_insert_id function is it possible that
the query can return the insert id from another insert performed by a
another user of the database which occured after the initial insert by
the first user but b4 the insert_id part can be queried.


No, mysql_insert_id() in the same script always gets the value of the last
query performed by that specific script, not by other connections to the
database.

Grtz,
--
Rik Wasmus
Jun 13 '06 #2

P: n/a
"monomaniac21" <mc******@googlemail.com> wrote in
news:11**********************@f6g2000cwb.googlegro ups.com:
Hi all

With regard to mysql's mysql_insert_id function is it possible that the
query can return the insert id from another insert performed by a
another user of the database which occured after the initial insert by
the first user but b4 the insert_id part can be queried.


You won't have any problems if you're running it immediately after the
query.

--
Karl Groves
www.karlcore.com
Jun 13 '06 #3

P: n/a
>> With regard to mysql's mysql_insert_id function is it possible that the
query can return the insert id from another insert performed by a
another user of the database which occured after the initial insert by
the first user but b4 the insert_id part can be queried.


You won't have any problems if you're running it immediately after the
query.


In the database world, there is no "immediately after". It's always
possible for someone else to get in a query between any two of
yours. It's up to locking (implicit or explicit) or transactions
to prevent bad effects on the data from this by delaying execution
of one until another finishes.

mysql_insert_id() returns the last insert id ON THIS CONNECTION.
So, as long as you keep the connection open (which probably won't
be beyond the processing of the PHP page: with persistent connections,
you are NOT guaranteed to get the same connection next time), you
can wait as long as you want to call mysql_insert_id().

Gordon L. Burditt
Jun 13 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.