How can I get the ID of the row that I just inserted? I am using a PDO statement where I can insert a name and email into a table.
$dbh = new PDO();
$dbh->prepare ("INSERT INTO `table` (`name`, `email`) VALUES (:name, :email);");
// execute
$dbh->execute(array(':name' => 'John Doe', ':email' => 'johndoe@gmail.com'));
The table also has an auto increment id column.
How can I get the id of the row that was just created? I have read about lastInsertId()
, but won't that sometimes give the wrong value if two clients insert a row at the same time?