mysqli_result::fetch_assoc
mysqli_fetch_assoc
Fetch a result row as an associative array
&reftitle.description;
&style.oop;
arraymysqli_result::fetch_assoc
&style.procedural;
arraymysqli_fetch_assoc
mysqli_resultresult
Returns an associative array that corresponds to the fetched row or &null;
if there are no more rows.
&database.field-case;
&database.fetch-null;
&reftitle.parameters;
&mysqli.result.description;
&reftitle.returnvalues;
Returns an associative array of strings representing the fetched row in the result
set, where each key in the array represents the name of one of the result
set's columns or &null; if there are no more rows in resultset.
If two or more columns of the result have the same field names, the last
column will take precedence. To access the other column(s) of the same
name, you either need to access the result with numeric indices by using
mysqli_fetch_row or add alias names.
&reftitle.examples;
&style.oop;
query($query)) {
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);
}
/* free result set */
$result->free();
}
/* close connection */
$mysqli->close();
?>
]]>
&style.procedural;
]]>
&examples.outputs;
A mysqli_result example comparing iterator usage
query('SELECT user,host FROM mysql.user') as $row ) {
printf("'%s'@'%s'\n", $row['user'], $row['host']);
}
echo "\n==================\n";
// Not using iterators
$result = $c->query('SELECT user,host FROM mysql.user');
while ($row = $result->fetch_assoc()) {
printf("'%s'@'%s'\n", $row['user'], $row['host']);
}
?>
]]>
&example.outputs.similar;
&reftitle.seealso;
mysqli_fetch_array
mysqli_fetch_row
mysqli_fetch_object
mysqli_query
mysqli_data_seek