Call to a member function fetch() on a non-object异常
程序员文章站
2022-03-28 17:40:27
...
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 指令错了,自然后继代码也要出错
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 指令错了,自然后继代码也要出错
相关文章
相关视频
下一篇: php 实现打印预览的效能
推荐阅读
-
jQuery的$.get()函数不执行以及php端报错Uncaught Error: Call to a member function bind_param() on boolean in...
-
php用mysqli模块连数据库Fatal error: Call to a member function query() 。解决思路
-
求大神纠错,多谢!Fatal error: Call to a member function query() on a non-object
-
Call to a member function fetch() on a non-object异常
-
Fatal error: Call to a member function fetch_array() on a non-object in 62 line
-
Wordpress PHP Fatal error: Call to a member function get()
-
php中出现“Call to a member function Execute() on a non-object”的有关问题
-
Fatal error: Call to a member function fetch_array() on a non-object in 62 line
-
如何总是遇见这类function query(),function fetch_array()这类异常呢
-
Call to undefined function bcompiler_write_header() 异常如何解决