enfaite je viens de me rendre compte que j'ai l'erreuruniquement quand je fais appel a ma fonction dans index.php. Pour la millièmes fois j'ai modifier mon code je passe cette fois ci par un tableau qui me sembler plus simple ben non j'ai une autre erreurCitation:
Fatal error: Call to a member function prepare() on a non-object in /home/www/test3/includes/requete_sql.php on line 21
Citation:
Warning: Invalid argument supplied for foreach() in /home/www/test3/includes/index.php on line 6
requete_sql.phpCode:
1
2
3
4
5
6
7
8 <?php require_once('includes/requete_sql.php'); $conn = db_connect(); $news = affiche_art(); foreach ($news as $n) { echo $n['titre']; } ?>
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 function affiche_art($titre_art, $article_art){ global $conn; $bdd = $conn; $news = array(); $sql = "SELECT * FROM ". PREFIX ."blog WHERE titre = :titre AND article = :article"; $req = $bdd->prepare($sql); $req->bindValue('titre', $titre_art, PDO::PARAM_STR); $req->bindValue('article', $article_art, PDO::PARAM_STR); $req->execute(); while ($donnees_art = $req->fetch()){ $news[] = $donnees_art; } $req->closeCursor(); return $donnees_art; }