PHPを勉強中のものですが、なぜエラーになっているのかわかりません。
http://ponk.jp/php/basic/blogこのサイトのblog/index.phpを参考にブログサイトを作っている最中です。
宜しくお願いします。
###発生している問題・エラーメッセージ
ORDER BY no DESCを消しても、~ near '' at line 1 というエラーが出ます。
エラーメッセージ
Connection failed:SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ORDER BY no DESC' at line 1
###該当のソースコード
try{
$dbh = new PDO($dsn, $user, $password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt= $dbh->query("SELECT * FROM image_put ORDER BY id DESC");
$stmt->execute();
$posts=$stmt->fetchAll(PDO::FETCH_ASSOC);
for($i=0; $i < count($posts); $i++){
$stmt= $dbh->query("SELECT * FROM comment WHERE post_no={$posts[$i]['no']} ORDER BY no DESC");
$posts[$i]['comments']=$stmt->fetchAll(PDO::FETCH_ASSOC);
}
}catch( PDOException $e ) {
echo 'Connection failed:'.$e->getMessage();
exit;
}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/22 11:57