Jump to content

Archived

This topic is now archived and is closed to further replies.

digitalgod

mysql_insert_id() or last_insert_id() ?

Recommended Posts

Which one should I use?

I have a query that inserts some info into a table named nights, when that query is done I have another one that inserts info into a table named rTables, in rTables I also have to insert the id  of the last inserted row. If i I use mysql_insert_id() it might give me the id of another table if someone else is doing something on the site.

I was wondering if LAST_INSERT_ID() does the same thing.. and what would be the best way of getting the id of the last row added in a table

Share this post


Link to post
Share on other sites
mysql_insert_id() returns the last value for the current db connection so is unaffected by anyone else.

Share this post


Link to post
Share on other sites
mysql_insert_id() is the one you want. It will only retrieve the last id generated for the corrent connection. LAST_INSERT_ID will retrieve the last (global) insert id.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.