pdo-database-class
pdo-database-class copied to clipboard
Get last insert ID for transaction
How can I get the last ID using a transaction?
$db->startTransaction();
...
if (!$db->insert('myTable', $insertData)) {
//Error while saving, cancel new record
$db->rollback();
} else {
//OK
$db->commit();
}
If I do:
$id = $db->insert('myTable', $insertData)
I get duplicate inserts
Refactored with php 8.4+ support. Please, check the new version.