I have a table which has got a column with AUTO INCREMENT
. I have to retrieve the value of this column when inserting a new row (i need the value of the new row). I've read a lot about it and found different solutions, one is to use SELECT LAST_INSERT_ID()
. I've heard many different things about this. Can I or can i not use this? I am worried that another connection may insert a new row before I am able to call SELECT LAST_INSERT_ID()
, and therefore get the wrong ID.
To sum up, is it safe to use SELECT LAST_INSERT_ID()
? If not, how can I retrieve the last inserted id in a safe way?