可捕获的致命错误:传递给...的参数1必须是...的实例,给定布尔值,在...中调用......并在...中定义

可捕获的致命错误:传递给...的参数1必须是...的实例,给定布尔值,在...中调用......并在...中定义

问题描述:

I have added a CMS to my server. I am just wondering why I keep getting this error on a Page to purchase a subscription.

This is the error;

Catchable fatal error: Argument 1 passed to ObjectArray::fromMySQLiResult() must be an instance of
mysqli_result, boolean given, called in
C:\inetpub\wwwroot\model\FactoryObjects\User.php on line 71
and defined in C:\inetpub\wwwroot\lib\ObjectArray.php on line 284

Line 71 has the following;

public function getOrders() {
    $objectArray = new ObjectArray();
    $result = $this->getConnection()->query("SELECT * FROM vip_orders WHERE user_id =
    '" . $this->id. "'");
    $objectArray->fromMySQLiResult($result); (<Line 71<)
    return $objectArray;
}

Line 284 has the following;

public function fromMySQLiResult(mysqli_result $result) (<Line 284<)
{
    $this->clear();
    while ($row = $result->fetch_object())
    {
        $this->add($row);   
    }
    return $this;
}

Please let me know if any other information is necessary for you to help me fix this error!

Thanks!

(Note: For those assisting, could you please explain what exactly is the problem? For example, what the function is and why it is not working, thank you.)

Your definition of fromMySQLiResult(mysqli_result $result) states that the function requires a parameter of type mysqli_result. However, you are passing the result of mysqli::query() which might also be of type boolean in case of failure.

To prevent the error, make sure $result is actually a query result similar to the example in the documentation:

if ($result) {
    $objectArray->fromMySQLiResult($result);
} else {
    // handle error
}