I can’t find any information on how to get the last inserted record with pdo_mysql.
The phpdelusion site references using [PDO::lastInsertId] but it doesn’t give any info for newbies like me on how this is accomplished.
- Do I add [PDO::lastInsertId] to my existing options?
$options = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, ];
- How do I reference this in a php code query? Would this code work without the above being added to options?
$id = $pdo->lastInsertId();
Note: Since I’m using PHP to run the query, I thought this should belong in the PHP forum. If I am wrong, please let me know and I will move it to the Database forum.