From 8a63019d0d2821c092b6002415f24fa348d0f9ac Mon Sep 17 00:00:00 2001 From: "Paul M. Jones" Date: Wed, 4 Apr 2018 07:54:59 -0500 Subject: [PATCH] add Connection::getLastInsertId() --- src/Connection.php | 5 +++++ tests/ConnectionTest.php | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/src/Connection.php b/src/Connection.php index 7f7ca11..1966c8e 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -57,6 +57,11 @@ public function getPdo() : PDO return $this->pdo; } + public function getLastInsertId(string $name = null) : string + { + return $this->pdo->lastInsertId($name); + } + public function perform( string $statement, array $values = [] diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index e645ddd..4da999c 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -65,6 +65,12 @@ public function testGetPdo() $this->assertSame($this->pdo, $this->connection->getPdo()); } + public function testGetLastInsertId() + { + $actual = $this->connection->getLastInsertId(); + $this->assertEquals(10, $actual); + } + public function testPerform() { $stm = $this->connection->perform("SELECT * FROM pdotest WHERE id = ?", [1]);