mysqli Fetch Methods

If you prefer different MySQL fetch methods, they're also in mysqli. Given the same query of SELECT username FROM users, these example functions all print the same results:
// Fetch numeric arrays:

while ($row = mysqli_fetch_row($result)) {

    print $row[0] . "\n";

}



// Alternative syntax:

while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) {

    print $row[0] . "\n";

}



// Alternative associative array syntax:

while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {

    print $row['username'] . "\n";

}



// Both numeric and associative:

while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {

    print $row[0] . "\n";

    print $row['username'] . "\n";

}



// Fetch as "object"

while ($row = mysqli_fetch_object($result)) {

    print $row->username . "\n";

}