0

lets say my code is:

$req = $bdd->prepare('INSERT INTO test(name, surname) VALUES(:name, :surname)');
$req->execute(array(
    'name' => $name,
    'surname' => $surname));

And my table test has an auto increment field named id

What is the best way to get the 'id' corresponding to $req?

4

1 回答 1

3

PDO 有一个方法:

$id = $pdo->lastInsertId();

或者在你的情况下:

$id = $bdd->lastInsertId();

您可以在此处找到有关 lastInsertID 方法的更多信息。

于 2013-09-02T21:33:00.733 回答