I’m trying to get the last id after a SQLite INSERT. After a lot of Googling and trial and error,I got.
$db = new PDO('sqlite:events.sqlite');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = 'INSERT INTO events
(evdate, evdesc)
VALUES
(:evdate, :evdesc)';
$stmt = $db->prepare($query);
$stmt->bindParam('evdate', $evdate, PDO::PARAM_STR);
$stmt->bindParam('evdesc', $evdesc, PDO::PARAM_STR);
$stmt->execute();
$lastid = $db->lastInsertRowID();
The INSERT works but not the lastInsertRowID(). I get an error Call to undefined method PDO::lastInsertRowID().
After further Googling it seems the PDO methods and lastInsertRowID() are in different classes. So I’m putting my hands up and crying, help!