File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 88use ipl \Sql \Contract \Adapter ;
99use ipl \Sql \Contract \Quoter ;
1010use ipl \Stdlib \Plugins ;
11+ use LogicException ;
1112use PDO ;
1213use PDOStatement ;
1314
@@ -438,6 +439,25 @@ public function insert($table, $data)
438439 return $ this ->prepexec ($ insert );
439440 }
440441
442+ /**
443+ * Get the ID of the last inserted row
444+ *
445+ * @param ?string $name The name of the sequence object from which the ID should be returned.
446+ *
447+ * @throws LogicException If no connection to the database is established
448+ * @return false|string
449+ */
450+ public function lastInsertId (?string $ name = null ): false |string
451+ {
452+ if ($ this ->pdo === null ) {
453+ throw new LogicException (
454+ 'Cannot get last insert ID because no connection to the database is established. '
455+ );
456+ }
457+
458+ return $ this ->pdo ->lastInsertId ($ name );
459+ }
460+
441461 /**
442462 * Update table rows with the specified data, optionally based on a given condition
443463 *
You can’t perform that action at this time.
0 commit comments