In my mysql table i have an id-column which is set to autoincrement.
then i do queries like this:
INSERT INTO table (id, foo) VALUES (”, ‘bar’)
how can i then safely find out which id was generated with this insert?
if i just query the last id this might not be safe, since another insert could have happened in the meantime, right?
Advertisement
Answer
There’s a PHP and also a MySQL function for this: mysqli_insert_id()
and PDO::lastInsertId()
.