Maison  >  Article  >  développement back-end  >  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 13:20:091756parcourir

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 指令错了,自然后继代码也要出错

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Article précédent: 中文验证码如何选取 Article suivant: php 数目字逗号分节