I executed a query which will insert an image link and username into a table:
INSERT into pictures set src = 'image link', username = 'acc'
I want to display that image after the query is executed (from table), or to get ID
(I tried mysql_insert_id()
, but what if 3 or more users will execute the query at the same time, which id will I get?
Thanks.
If you are AUTO_INCREMENT with column, then you can use last_insert_id() method. This method gets the ID of the last inserted record in MySQL.
If you insert a record into a table that contains an AUTO_INCREMENT column, you can obtain the value stored into that column by calling the mysql_insert_id() function.
The LAST() function in Structured Query Language shows the last value from the specified column of the table.
It gets the last ID from your database session, so if other users insert, that does not matter :D.
As long as your session does not do other insert (thats quite unlikely in mosts systems) in between you're fine
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With