Using Prepared Statement, how I return the id of the inserted row?

Viewed 48223

I want retrieve the id of a inserted row in the database, but I don't know how to do this.

I tried to return using the SQL clause RETURNING id, but not works.

How I can return the id after the insertion of a row?

3 Answers

You need to use:

$stmt = $db->prepare("SQL Query");
$stmt->execute();
$id = $db->lastInsertId();
Related