je sais que cette erreur est courante mais dans mon cas je pense c'est different et j'espere que vous allez pouvoir m'aider!
je veux filtrer par rapport à la session d'un Admin et je vois si l'adminitrateur n'a pas de publication j'ai butté sur cette erreur "Call to a member function fetchAll() on bool" par conte s'il en a elle me retourne le resultat!
mon code:
//Trouver les articles et les catégories avec la pagination en fonction de la session de l' ADM et retourner les resultats
public function findPaginatedSession($session){
$paginated = new Paginated(
" SELECT post.id, post.name, post.content, post.created_at, users.username
FROM post
INNER JOIN users
ON post.session_admin = users.id
WHERE publier = '0' AND post.session_admin = $session
ORDER BY post.created_at DESC",
"SELECT COUNT(id) FROM {$this->table}"
);
$post = $paginated->getItems($this->class);
(new CategoryTable($this->pdo))->hydratePost($post);
return [$post , $paginated];
}
// Rechercher les articles avec la pagination
public function getItems($classMapping): array
{if($this->items === null){
$currentPage = Url::getPositiveInt('page', 1);
$page = $this->getPage();
if($currentPage > $page){
throw new \Exception("Cette page n'existe pas");
}
$offset = $this->perPage * ($currentPage -1);
return $this->items = $this->pdo->query(
$this->query .
" LIMIT {$this->perPage} OFFSET $offset")
->fetchAll(PDO::FETCH_CLASS, $classMapping);
}
return $this->items;
}
// Rechercher les categorie a partir d'id des articles trouver
public function hydratePostSess(array $post){
$postById = [];
foreach($post as $posts){
$posts->setCategories([]);
$postById[$posts->getId()] = $posts;
}
$categorie = $this->pdo
->query('SELECT c.*, pc.post_id
FROM post_category pc
JOIN category c ON c.id = pc.category_id
WHERE pc.post_id IN (' . implode(',', array_keys($postById)) . ')
')->fetchAll(PDO::FETCH_CLASS, $this->class); /// elle m'a indiqué que l'erreur se trouve ici
foreach($categorie as $category){
$postById[$category->getPostId()]->addCategory($category);
}
}