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?

Ali
  • 2,012
  • 3
  • 25
  • 41
  • 2
    So, are you worried that if you have too many users hitting this page, that `lastInsertId` will return the wrong value? – gen_Eric Sep 03 '14 at 17:03
  • @RocketHazmat yup, exactly... – Ali 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
  • 4,445
  • 6
  • 44
  • 78