Cannot use object of type PDOStatement
Fatal error: Cannot use object of type PDOStatement on vueBillet.php on line 2
Voici mon fichier vueBillet.php
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
| <html lang="fr">
<?php $titre = "Mon Blog - " .$billet['titre']; ?>
<?php ob_start(); ?>
<article>
<header>
<meta charset="UTF-8" />
<link rel="stylesheet" href="contenu/style.css" />
<title>Mon Blog</title>
<h1 class="titreBillet"><?= $billet['titre'] ?></h1>
<time><?= $billet['date'] ?></time>
</header>
<p><?= $billet['contenu'] ?></p>
</article>
<hr />
<header>
<h1 id="titreReponses">Réponses à <?= $billet['titre'] ?></h1>
</header>
<?php foreach ($commentaires as $commentaire): ?>
<p><?= $commentaire['auteur'] ?> dit :</p>
<p><?= $commentaire['contenu'] ?></p>
<?php endforeach; ?>
<?php $contenu = ob_get_clean(); ?>
<?php require 'vueGlobale.php'; ?>
</html> |
mon fichier vue globale :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| <html lang="fr">
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="contenu/style.css" />
<title>Mon Blog</title>
</head>
<body>
<div id="global">
<header>
<a href="index.php"><h1 id="titreBlog">Mon Blog</h1></a>
<p>Je vous souhaite la bienvenue sur ce modeste blog.</p>
</header>
<div id="contenu">
<?php echo $contenu;?>
</div> <!-- #contenu -->
<footer id="piedBlog">
Blog réalisé avec PHP, HTML5 et CSS.
</footer>
</div> <!-- #global -->
</body>
</html> |
voici ma list des requêtes pour récupérer les billet et se connecter a la BDD :
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
| <?php function getBDD(){
$bdd = new PDO('mysql:host=localhost;dbname=monblog;charset=utf8',
'root', '', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
return ($bdd);
}
?>
<?php
function getBillet($idBillet) {
$sql = 'select BIL_ID as id, BIL_DATE as date,'
. ' BIL_TITRE as titre, BIL_CONTENU as contenu from T_BILLET'
. ' where BIL_ID='.$idBillet;
$billet = $this->executerRequete($sql, array($idBillet));
if ($billet->rowCount() == 1)
return $billet->fetch();
else
throw new Exception("Aucun billet ne correspond à l'identifiant '$idBillet'");
}
?>
<?php function getBillets () {
$bdd = getBDD();
$billets = $bdd->query('select BIL_ID as id, BIL_DATE as date,'
. ' BIL_TITRE as titre, BIL_CONTENU as contenu from T_BILLET'
. ' order by BIL_ID desc');
return($billets);
}
?>
<?php
function getCommentaires($idBillet) {
$bdd = getBdd();
$commentaires = $bdd->prepare('select COM_ID as id, COM_DATE as date,'
. ' COM_AUTEUR as auteur, COM_CONTENU as contenu from T_COMMENTAIRE'
. ' where BIL_ID='.$idBillet);
$commentaires->execute(array($idBillet));
return $commentaires;
}
?> |