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
  •  | 
  •  

Question

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()

Was it helpful?

Solution

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
  ...
}

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top