doulu1325 2013-01-14 15:58
浏览 102
已采纳

“在非对象上调用成员函数fetch_row()”尽管有错误处理[关闭]

I want to execute a query but php/mysql throws

Call to a member function fetch_row() on a non-object

even though

if(!$results) 

should filter out empty results. The error message points to

$row = $results->fetch_row();

This is the whole code:

<?php
$query = 'DELETE FROM `products` WHERE `company` ='.$id_nummer;

$results = $link->query($query);
if(!$results)
{
  echo $link->error;
}
else
{
  $row = $results->fetch_row();
  $wanted_result = $row[0];
}
?>

Where is the cause for this?

EDIT: I solved it by replacing

if(!$results)

with

if(!is_object($results))

and it works.

  • 写回答

2条回答 默认 最新

  • dongyuanliao6204 2013-01-14 16:07
    关注

    You are trying to fetch a row from a a query as an object, however the query that you are making is a DELETE which doesn't return values that can be fetch as a row, but a boolean (TRUE or FALSE) that is the result of the query being successful or not. In this case, $result should return the value TRUE or FALSE, that can be used like this for example:

    <?php
    $query = 'DELETE FROM `products` WHERE `company` ='.$id_nummer;    
    $results = $link->query($query);
    
    if(!$results) {
        echo $link->error;
    } else {
        echo "Company id:".$in_number." successfully deleted."
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题