problème PDO

Par jamal0, il y a 13 ans


j'ai suivi le tutoriel sur la construction de système de panier
mais j'ai une erreur:
"Fatal error: Call to a member function query() on a non-object in"
et voila le code:
public function query($sql){
$req=$this->bd->prepare($sql);
$req->execute();
return $req->fetchAll(PDO::FETCH_OBJ);
}

je ne sais pas d'ou viens l'erreur .
merci bien d'aider.

5 réponses

Nairolf, il y a 13 ans

Tu l'appelles comment ta fonction query?

jamal0, il y a 13 ans

oui

jamal0, il y a 13 ans

mais le problème et dans la ligne
"""$req=$this->bd->prepare($sql); """
ou ça m'affiche
Fatal error: Call to a member function prepare() on a non-object in

RedaElkhayat, il y a 13 ans

Salut, passe nous le reste du code.

Nairolf, il y a 13 ans

En fait cette erreur vient du fait que $this ici ne serait pas un objet, ou que bd n'existe pas dans ton objet ici.