tommyknocker / pdo-database-class

PHP PDO Wrapper which utilizes PDO and prepared statements
GNU Lesser General Public License v3.0
68 stars 46 forks source link

Get last insert ID for transaction #5

Open tmblog opened 5 years ago

tmblog commented 5 years ago

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