php fetch_assoc explained code example
Example 1: mysqli fetch assoc
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 50,5";
if ($result = $mysqli->query($query)) {
while ($row = $result->fetch_assoc()) {
printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);
}
$result->free();
}
$mysqli->close();
?>
Example 2: fetch assoc oop
public mysqli_result::fetch_assoc ( ) : array