Hey guys Im currently trying to debug some code for a mysqli encapsulation class. Ive run into a problem described here have tried a few solutions with this being the latest iteration and (doesn’t seem to work):
$this->result = new stdClass();
foreach($res = $this->conn->query($sql) as $key => $value) {
$this->result->$key = $value;
}
If anyone knows a way to store the results somehow or create a system with pointers and $result->free_result(); bring called at sometime it would be much appreciated. Im a little stumped and very short for time.
Thanks in advance!
EDIT as of right now my original implementation seems to be working not sure if this will hold true through testing. Currently I have a custom $this->query() function calling mysqli->query and storing the results in $this->result, however under some circumstances it seems $this->result becomes unset. Going to keep testing/debugging what I have and see if it happens again. Thanks to those who answered 🙂
EDIT 2 Through a fair bit of trial and error Ive traced the issue I was having back to a SQL query behaving oddly. It seems its not possible to store the resulting object from mysqli::query() without issue(?).
Your example coding isn’t fetching rows. You’ll need to do that and one of the options is to fetch as objects: