This question already has an answer here:
I am trying to retrieve my database rows using OOP I keep getting an error though. I feel like I am missing something simple to make this work. My code is below:
Class CommentFactory {
public function getImage(PDO $conn){
$stmt2 = $conn->prepare('SELECT * FROM `pictures`');
$stmt2->execute();
return $stmt2;
}
}
$statement = new CommentFactory();
$statement->getImage($conn);
while ($idOfComment = $statement->fetch(PDO::FETCH_ASSOC)) {
echo $idOfComment['photo_id'];
}
The error I am getting is:
Fatal error: Call to undefined method CommentFactory::fetch() in /var/www/CommentSystem/includes/Classes.php on line 29
I just recently began trying to program in OOP so my understanding is still vague.
</div>