Bonsoir à tous,
J'essaye de comprendre la programmation POO, j'ai créer une class qui a plusieurs fonction. Mon code base fonctionne le voici :
Par contre, si je veux sortir uniquement les valeurs de deux champs et les récupérer via mes getters ça ne fonctionne plus. Voici mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 public function setId($id){$this->id = $id;} public function affComm(){ $db =Database::connect(); $db->exec("SET CHARACTER SET utf8"); if($this->id ===''){ $stmt = $db->prepare("SELECT * FROM communication"); } else{ $stmt = $db->prepare("SELECT * FROM communication where id = :id "); $stmt->bindValue(":id",$this->id,PDO::PARAM_INT); } $stmt->execute(); $comm = $stmt->fetchall(); $stmt->closeCursor(); return $comm; }
J'aimerai soit afficher tout, soit récupérer que certains éléments.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 public function setId($id){$this->id = $id;} public function getNom(){return $this->nom;} public function setNom($nom){$this->nom = $nom;} public function getCorps(){return $this->corps;} public function setCorps($corps){$this->corps = $corps;} public function affComm(){ $db =Database::connect(); $db->exec("SET CHARACTER SET utf8"); if($this->id ===''){ $stmt = $db->prepare("SELECT * FROM communication"); } else{ $stmt = $db->prepare("SELECT * FROM communication where id = :id "); $stmt->bindValue(":id",$this->id,PDO::PARAM_INT); } $stmt->bindParam(':nom', $this->nom,PDO::PARAM_STR); //J'essaye de récupérer une valeur et de l'affecter à son getter. $stmt->bindParam(':corps', $this->corps,PDO::PARAM_STR);//J'essaye de récupérer une valeur et de l'affecter à son getter. $stmt->execute(); // $this->nom = $comm['nom']; // Ne fonctionne pas nom plus // $this->corps = $comm['corps'];// Ne fonctionne pas nom plus $comm = $stmt->fetchall(); $stmt->closeCursor(); return $comm; }
À l'aide s' il vous plait, un tout grand merci d'avance
Partager