Fatal error: Call to a member..
Bonjour à tous , je débute en Php. Je voudrais lire les infos de ma base sql mais je bloque :
Fatal error: Call to a member function prepare() on a non-object in class_livre.php on line 9
Je déjà eu cette erreur plusieurs fois, mais la je bute dessus :/
Code:
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
|
//Fichier class livre
<?php
class livre
{
private $selectAll;
public function __construct($db)
{
$this->selectAll = $db->prepare("select * from livre");
}
public function selectAll()
{
$this->selectAll->execute();
return $this ->selectAll->fetchAll();
}
}
// Le fichier pour lire
$livre = new livre($db);
$listelivre=$livre -> selectAll();
echo "<table>
<tr>
<th>id</th>
<th>pseudo</th>
<th>email</th>
<th>message</th>
</tr>";
foreach ($listelivre as $unlivre)
{
echo '<tr><td>'.$unlivre['idmessage']
.'</td><td>'.$unlivre['pseudo']
.'</td><td>'.$unlivre['email ']
.'</td><td>'.$unlivre['message']
.'</td></tr>'."\n";
}
echo '</table>';
?>
?> |