How do I get a mysqli_result when the mysqli result instance is wrapped in a third-party class?

StackOverflow https://stackoverflow.com/questions/23376077

  •  12-07-2023
  •  | 
  •  

문제

Usually when I use mysqli, my queries are as following:

$query = $mysql->query("SELECT * FROM .........");
$data = $mysql->fetch_assoc();

However, that's not possible using

$mQuery = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE `order_id` = $orderid");
while($mData = $mQuery->fetch_assoc()) {
...
}

How can I convert this into a functional code?

I get the following error:

Fatal error: Call to undefined method stdClass::fetch_assoc()

도움이 되었습니까?

해결책

There is no difference: In the first example you are calling methods on the $mysql object, so in the second example you should do the same:

$mQuery = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE `order_id` = $orderid");
while($mData = $this->db->fetch_assoc()) {
  //           ^^^^^^^^^ The same object of which you called the query method
  ...
}

다른 팁

The function behind $this->db->query needs to return a mysqli_result instance instead of returning a stdClass.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top