Home > Article > Backend Development > The difference between mysqli_fetch_assoc() and mysqli_fetch_row() in php_PHP tutorial
Using mysqli_fetch_assoc() and mysqli_fetch_row() both returns the query results into an array. Both return the first row and then move the pointer down one row.
Difference: mysqli_fetch_assoc() uses keyword index to obtain the value. For example:
$row = $result->fetch_assoc();
echo $row['username'];
But mysqli_fetch_row() uses a numeric index to obtain the value. For example:
$row = $result->fetch_row();
echo $row[0];//Note: "0" means the first field in the table (i.e. username is the the first field).
There is also a function: mysqli_fetch_object() to get a row back into an object, and then get the value through a class, for example:
$row = $result->fetch_object();
echo $row->username;