Add lastInsertId

This commit is contained in:
Jay Trees 2022-02-24 10:39:59 +01:00
parent eedaae004f
commit 28247964fa

View file

@ -14,6 +14,8 @@ class Database
{ {
public \PDO $pdo; public \PDO $pdo;
private int $lastInsertId;
public function __construct( public function __construct(
public string $host, public string $host,
public string $database, public string $database,
@ -26,11 +28,20 @@ class Database
$this->pdo = new \PDO($dsn, $this->user, $this->password, $options); $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, $query,
\PDO::FETCH_ASSOC \PDO::FETCH_ASSOC
); );
$this->lastInsertId = $this->pdo->lastInsertId();
return $statement;
}
public function lastInsertId(): int
{
return $this->lastInsertId;
} }
} }