本文給大家講述php連接數據庫報錯"Fatal error: Call to a member function query() on a non-object in"的原因。
在用php查詢數據庫的時候,小編遇到報錯如下:
Fatal error: Call to a member function query() on a non-object in D:/test/edit.php on line 16
經過檢查,找到問題原因:
$dbh->query("SELECT * from tb_name")
我這句中的$dbh是不存在的。
請注意$dbh必須先創建,如:
$dbh=new PDO('mysql:host=127.0.0.1; dbname=dbname','username','password');
Call to a member function query() on a non-object in原因
新聞熱點
疑難解答