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 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了