在php oop中使用mysqli方法

在php oop中使用mysqli方法,php,oop,mysqli,fetch,Php,Oop,Mysqli,Fetch,我有一个问题:为什么我不能在脚本中使用方法fetch_object()。我有一个方法: public function magazyn() { //return 'magazyn'; $this->magazyn = $this->conn->prepare("SELECT * FROM `products` ORDER BY `nazwa`"); //$this->magazyn->bind_param('ssss', $id, $nazw

我有一个问题:为什么我不能在脚本中使用方法fetch_object()。我有一个方法:

public function magazyn() {
    //return 'magazyn';
    $this->magazyn = $this->conn->prepare("SELECT * FROM `products` ORDER BY `nazwa`");
    //$this->magazyn->bind_param('ssss', $id, $nazwa, $kategoria, $sn);
    $this->magazyn->execute();
    $this->magazyn->store_result();
    //return $this->magazyn;

    if ($this->magazyn->num_rows > 0) {

        $rows = array();
        while ($row = $this->magazyn->fetch_object()) {
            echo $rows[] = $row;

        }

    } else {
        echo "Brak produktw w bazie";
    }
}
脚本返回错误:

致命错误:未捕获错误:调用未定义的方法 mysqli_stmt::在中获取_对象()

但我可以用“准备”这个例子:


不能直接在语句对象上使用
fetch\u object
。正如这里所说:

和在文件中

您应该获得结果并将fetch_对象应用于该结果

/* execute query */
$stmt->execute();

$result = $stmt->get_result();

/* now you can fetch the results into an object */
while ($myrow = $result->fetch_object()) {

$poop=$this->magazyn->store_result()
然后
while($row=$poop->fetch_object())
基本上是因为
mysqli_stmt
对象没有名为
fetch_object
/* execute query */
$stmt->execute();

$result = $stmt->get_result();

/* now you can fetch the results into an object */
while ($myrow = $result->fetch_object()) {