PDO を使用してテーブルのすべての行をエコーアウトしようとしていますが、問題が発生しています。
古いやり方で、私はそれをしただろう
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)){
$title= $row['title'];
$body= $row['body'];
}
しかし、私は PDO を試しています。
$result = $db->prepare("SELECT title, body FROM post");
$result->execute();
while ($row = $db->fetchAll(PDO::FETCH_ASSOC))
{
$title = $row['title'];
$body = $row['body'];
}
echo $title;
echo $body;
Call to undefined method PDO::fetchAll() を与え続けます
マニュアルに記載されている例を実行する
<?php
$sth = $dbh->prepare("SELECT name, colour FROM fruit");
$sth->execute();
/* Fetch all of the remaining rows in the result set */
print("Fetch all of the remaining rows in the result set:\n");
$result = $sth->fetchAll();
print_r($result);
?>
動作しますが、 $row=['blah']; のように個々の列を制御できるとは思いません。私は?また、このように出力されます。かなり醜い:
Array ( [0] => Array ( [title] => これはデータベースに入力されたテストタイトルです[0]
これを行うために PDO を適切に使用するには、何をする必要がありますか?