public function findPostById($id) { $um = new PdoUserManager(); $stmt = self::$dtb->query('SELECT * FROM posts WHERE id = ' . intval($id)); $data = $stmt->fetch(PDO::FETCH_OBJ); $data = new Post($data->id, $data->title, $data->body, $data->publicationDate, $um->findUserById($data->userID)); $stmt->closeCursor(); return $data; }
public function findPostById($id) { $stmt = $this->dtb->prepare('SELECT * FROM posts WHERE id = :id'); $stmt->bindValue(':id', $id, PDO::PARAM_INT); $stmt->execute(); $UM = new PdoUserManager(); $CM = new PdoCommentManager(); $d = $stmt->fetch(PDO::FETCH_OBJ); $data = new Post($d->id, $d->title, $d->body, $d->publicationDate, $UM->findUserById($d->userID), $CM->findAllCommentsForPostId($d->id)); $stmt->closeCursor(); return $data; }
public function findCommentById($id) { $stmt = $this->dtb->prepare('SELECT * FROM comments WHERE postID = :pid'); $stmt->bindValue(':pid', $pid, PDO::PARAM_INT); $stmt->execute(); $data = array(); $um = new PdoUserManager(); $pm = new PdoPostManager(); $d = $stmt->fetch(PDO::FETCH_OBJ); $c = new Comment(); $c->setId($d->id); $c->setBody($d->body); //$c->setPost($pm->findPostById($d->postID)); $c->setUser($um->findUserById($d->userID)); $c->setPublicationDate($d->publicationDate); $data[] = $c; $stmt->closeCursor(); return $data; }