Question

I saw that the function mysqli_insert_id can return the last inserted or updated id.

But is it users safe? I mean, if some users at the same time insert or update query fires (on the same link) from different locations so it will return correct insert id to appropriate user?

Was it helpful?

Solution

Thanks to Your Common Sense comment, I saw that mysqli_insert_id is multi-user safe. If each user gets msqli link, the mysqli_insert_id returns the correct id, no metter how many users fires insert queries simultaneity.

OTHER TIPS

yes MySQLi_insert_id() is best i always use this code. that code send true value

Based on user opinions and my experience it's safe but you can always code your application to recheck it.

For example if you have table with fields (id, id_user, data1, data2, ...) and user makes you insert data in this table, you can launch mysqli_insert_id immediately after insert, get the record from table:

SELECT * from table WHERE id = $value_from_mysli_insert_id AND id_user = $current_user

And now you are sure that this is user's record. Of course you can also get the whole record and recheck if all data is the same as user inserted them into table

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top