当前位置: 代码迷 >> PHP >> Call to a member function fetch() on a non-object异常
  详细解决方案

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

热度:1037   发布时间:2012-08-26 16:48:05.0
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 指令错了,自然后继代码也要出错
  相关解决方案