From 28247964fa26b18ffec486e4be68a94702c6acb5 Mon Sep 17 00:00:00 2001 From: Jay Trees Date: Thu, 24 Feb 2022 10:39:59 +0100 Subject: [PATCH] Add lastInsertId --- src/classes/database.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/classes/database.php b/src/classes/database.php index d6760699..9d0856c7 100644 --- a/src/classes/database.php +++ b/src/classes/database.php @@ -14,6 +14,8 @@ class Database { public \PDO $pdo; + private int $lastInsertId; + public function __construct( public string $host, public string $database, @@ -26,11 +28,20 @@ class Database $this->pdo = new \PDO($dsn, $this->user, $this->password, $options); } - public function query(string $query): mixed + public function query(string $query): \PDOStatement { - return $this->pdo->query( + $statement = $this->pdo->query( $query, \PDO::FETCH_ASSOC ); + + $this->lastInsertId = $this->pdo->lastInsertId(); + + return $statement; + } + + public function lastInsertId(): int + { + return $this->lastInsertId; } }