Is there a mysqli_fetch_all() equivalent to return an array of objects?

Viewed 158

Is there a way to get the entire result set of a mysqli select statement in one call (like mysqli_fetch_all) but as an array of objects (instead of an array of associative arrays)? So that I don't have to write this:

$arr_objects = [];
while($obj = mysqli_fetch_object($result)){
    $arr_objects[] = $obj;
}
1 Answers

It's not possible to get an array of objects using mysqli_fetch_all(). The available options are: indexed array, associative array, or both.

Consider using the PHP Data Objects (PDO) interface, which has many more fetch modes and is thus superior to MySQLi in that regard.

Related