Home  >  Article  >  Backend Development  >  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:091756browse

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn