Bonjour, j'ai un soucis avec mon code php
J'ai mis un debug($data); pour voir ce qu'il y a dans ma variable $data
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 <?php class Authors { public $id; public $firstname; public $lastname; /** * __construct retourne un auteur * à partir de son id * * @param mixed $id * @return void */ public function __construct(int $id) { global $db; $id = str_secur($id); $reqAuthor = $db->prepare('SELECT * FROM authors WHERE id = ?'); $reqAuthor->execute(array($id)); $data = $reqAuthor->fetchAll(); debug($data); $this->id = $id; $this->firstname = $data["firstname"]; $this->lastname = $data["lastname"]; } /** * getAllAuthors retourne la * liste de tous les auteurs * * @return void */ static function getAllAuthors() { global $db; $reqAuthors = $db->prepare('SELECT * FROM authors'); $reqAuthors->execute([]); return $reqAuthors->fetchAll(); } } ?>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 $var = new Authors(1); debug($db); debug($var); exit;
Je sais pas vraiment où est le problème.
Merci d'avance pour votre aide
Partager