0

I've a database with hundreds of records which inserted in each seconds, I have the below insert query and I want to know the insert id of this query:

   $currQuery = $pdo->prepare("INSERT INTO some_table (...... )");
   $currQuery->execute("....");
   $queryInsertId = $pdo->lastInsertId();

I just want to know that is it safe to use lastInsertId() while I having hundreds of new records in every seconds? any ideas?

NullPointer
  • 1,924
  • 2
  • 20
  • 40
  • 1
    So, are you worried that if you have too many users hitting this page, that `lastInsertId` will return the wrong value? – Rocket Hazmat Sep 03 '14 at 17:03
  • @RocketHazmat yup, exactly... – NullPointer Sep 03 '14 at 17:06
  • [is it possible for mysqli_insert_id to return an incorrect id in high-traffic app](http://stackoverflow.com/questions/9315200/is-it-possible-for-mysqli-insert-id-to-return-an-incorrect-id-in-high-traffic-ap/9315402#9315402) – Mark Baker Sep 03 '14 at 17:38

1 Answers1

2

Yes it is safe. It returns the last insert id for the connection.

user3791372
  • 3,937
  • 3
  • 34
  • 68