2016-05-09 9 views
-2

私は質問があります:なぜ私のスクリプトでfetch_object()メソッドを使用することができません。 "準備"php oopでmysqliメソッドを使用

Fatal error: Uncaught Error: Call to undefined method mysqli_stmt::fetch_object() in

しかし、私は、例えば使用することができます:

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"; 
    } 
} 

スクリプトのリターンエラー:私は、メソッドを持って

$this->magazyn = $this->conn->prepare("SELECT * FROM `products` ORDER BY `nazwa`"); 
+0

'$糞=の$ this - > magazyn->のstore_result();'、次いで '($行= $ poop-> fetch_object())一方、' ' – Martin

+0

基本的mysqli_stmt'オブジェクトが持っていないため'fetch_object'と呼ばれるメソッド – RiggsFolly

答えて

1

あなたは文オブジェクトに直接fetch_objectを使用することはできません。それはここで言ったように:

Is it possible to use mysqli_fetch_object with a prepared statement

およびドキュメントの

http://php.net/manual/en/mysqli.prepare.php

あなたは結果を取得し、それにfetch_objectを適用する必要があります。

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

$result = $stmt->get_result(); 

/* now you can fetch the results into an object */ 
while ($myrow = $result->fetch_object()) { 
関連する問題