I recently found out that I can print results from database without using mysqli_fetch_object function.
So for example: Let's say we have simple sql select statment which would be executed by using something like this:
$conn = mysqli_connect('localhost', 'root', '', 'example_db');
$result = mysqli_query($conn, "SELECT * FROM users");
Next step would be something like this:
while($row = mysqli_fetch_object($result)) echo $row->username
Where username is corresponding column name in table of users.
Then I figured out this works too for printing it out:
foreach($result as $row) echo $row['username'];
After couple of var_dumps and fruther reading of php documentation. My only guess would be that this is possible because of this:
5.4.0 Iterator support was added, as mysqli_result now implements Traversable.
So if my claims are true. Is there any need for using something like
mysqli_fetch_object or similar function mysqli_fetch_array ?
foreach($resault as $row) echo $row['username'];- That$resaultis a typo, right?mysqli_resultobject, you're limited to array-formatted results, whereasmysqli_fetch_objectwill provide them as objects. If you're happy with that, then like you say, you can just iterate over it directly. It's very much just a matter of taste, though.