【发布时间】:2012-11-21 20:15:32
【问题描述】:
执行以下查询时出现致命错误:
$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();}
有谁知道是什么导致了这个错误?
【问题讨论】:
-
你忘记初始化$db了吗?
-
你是如何设置 $db 的?
标签: php pdo fatal-error