When using mysqli_fetch_object()
, you can pass the name of an object as the second parameter. By doing so, mysqli creates the corresponding object and automatically sets the variables.
objectname {
// No defined properties
}
(...)
$object = mysqli_fetch_object($result, "objectname");
Under the assumption that $result contains data for "forname" and "surname", we would now have access to:
$object->forename;
$object->surname;
Is it possible to fetch the data into an associative array instead? Like shown here:
objectname {
public $data = array();
}
(...)
$object = mysqli_fetch_object($result, "objectname");
And then having:
$object->data["forename"];
$object->data["surname"];
If not: What is the code, MySQLi uses to populate the object with mysqli_fetch_object()
? Considering that MySQLi is even able to change predefined private variables, it is a total mystery for me.