Heim  >  Artikel  >  Backend-Entwicklung  >  Call to a member function fetch() on a non-object异常

Call to a member function fetch() on a non-object异常

WBOY
WBOYOriginal
2016-06-13 10:38:242412Durchsuche

Call to a member function fetch() on a non-object错误
try{
$dsn = "mysql:host=localhost;dbname=db_upan";
$db = new PDO($dsn,"root","");
$sql = "select * form tb_uptype";
$statement = $db->query($sql);
while($result = $statement->fetch(PDO::FETCH_ASSOC )){
echo $result['genrename'];
}
$db = null;
  }catch (PDOException $e){
echo "发生错误。";
}
代码如上: 运行的时候提示错误Fatal error: Call to a member function fetch() on a non-object in C:\xampp\htdocs\upan\test.php on line 7;
请问这是什么原因啊? 坐等。。。

------解决方案--------------------
$sql = "select * from tb_uptype";
------解决方案--------------------
$sql = "select * form tb_uptype";
应为
$sql = "select * from tb_uptype";

sql 指令错了,自然后继代码也要出错

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn