以下のクエリを実行すると、致命的なエラーが発生します。
$stmt = $db->query('SELECT * FROM comments LIMIT 50');
while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo $result['name'] . ':' . strip_tags($result['message']);
}
戻り値:
Fatal error: Call to a member function query() on a non-object
$db を次のように設定します。
try {$db = new PDO('mysql:host=localhost;dbname=database', 'username', 'password');}
catch(PDOException $e) {echo $e->getMessage();}
このエラーの原因を知っている人はいますか?