Answer the question
In order to leave comments, you need to log in
How to get the id of the inserted row in the database?
I'm interested in the functions php.net/manual/ru/pdo.lastinsertid.php and
php.net/manual/ru/mysqli.insert-id.php .
For example, there is a script:
$db->query("INSERT ...");
$id = $db->lastInsertId();
Answer the question
In order to leave comments, you need to log in
lastInsertId (aka the LAST_INSERT_ID mysql function) is concurrency safe, returns the generated auto increment value for the previous query on that particular connection.
Therefore, if you do insert in one connection, then the subsequent lastInsertId through this connection is guaranteed to return the correct value.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question