db = Database::getConnection(); } public function getPosts(): array { $posts = []; $query = $this->db->query(<<rowCount()) throw new Exception("no entries available"); while($row = $query->fetchObject()) { $posts[] = new Post($row->id, $row->title, $row->content, $row->username, $row->stamp); } return $posts; } public function getPost($id): ?Post { $query = $this->db->prepare(<<bindParam(":id", $id, $this->db::PARAM_INT); $query->execute(); if(!$query->rowCount()) throw new Exception("no entry found"); $row = $query->fetchObject(); return new Post($row->id, $row->title, $row->content, $row->username, $row->stamp); } }