Skip to content

Commit b0ec22f

Browse files
committed
Connection: Add lastInsertId to the interface
Helps with static analysis and test doubles. (phpunit will not mock/stub this method unless declared)
1 parent 3f578b1 commit b0ec22f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/Connection.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,18 @@ public function insert($table, $data)
438438
return $this->prepexec($insert);
439439
}
440440

441+
/**
442+
* Get the ID of the last inserted row
443+
*
444+
* @param ?string $name The name of the sequence object from which the ID should be returned.
445+
*
446+
* @return false|string
447+
*/
448+
public function lastInsertId(string $name = null): false|string
449+
{
450+
return $this->pdo?->lastInsertId($name) ?? false;
451+
}
452+
441453
/**
442454
* Update table rows with the specified data, optionally based on a given condition
443455
*

0 commit comments

Comments
 (0)