現在下記のサイトを勉強しています。
ブログを作る
質問なのですが、テーブル名をpostの所をdai、commentの所をhenjiとしました。
そのようにしたら、サイトの下記の部分でエラーが出てしまい、どの部分を書き換えれば良いのか分からなくなり質問します。
phpmyadminからテーブル名を変えるのも考えましたが、結局意味がないと思い教えて頂きたいと思います。
blog/index.php
php
1<?php 2 $pdo = new PDO("mysql:dbname=blog", "root"); 3 $st = $pdo->query("SELECT * FROM post ORDER BY no DESC"); 4 $posts = $st->fetchAll(); 5 for ($i = 0; $i < count($posts); $i++) { 6 $st = $pdo->query("SELECT * FROM comment WHERE post_no={$posts[$i]['no']} ORDER BY no DESC"); 7 $posts[$i]['comments'] = $st->fetchAll(); 8 } 9 require 't_index.php'; 10?>
blog/t_index.php
php
1<!DOCTYPE html> 2<html> 3<head> 4<meta charset="utf-8"> 5<title>Special Blog</title> 6<link rel="stylesheet" href="blog.css"> 7</head> 8<body> 9<h1>Special Blog</h1> 10<?php foreach ($posts as $post) { ?> 11 <div class="post"> 12 <h2><?php echo $post['title'] ?></h2> 13 <p><?php echo nl2br($post['content']) ?></p> 14 <?php foreach ($post['comments'] as $comment) { ?> 15 <div class="comment"> 16 <h3><?php echo $comment['name'] ?></h3> 17 <p><?php echo nl2br($comment['content']) ?></p> 18 </div> 19 <?php } ?> 20 <p class="commment_link"> 21 投稿日:<?php echo $post['time'] ?> 22 <a href="comment.php?no=<?php echo $post['no'] ?>">コメント</a> 23 </p> 24 </div> 25<?php } ?> 26</body> 27</html>
エラーメッセージです
Fatal error: Uncaught Error: Call to a member function fetchAll() on boolean in /Applications/XAMPP/xamppfiles/htdocs/php/blog/index.php:4 Stack trace: #0 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/php/blog/index.php on line 4
回答3件
あなたの回答
tips
プレビュー