Which only returns one row time from the result set
$result = mysqli_query($link, "SELECT Code, Name FROM Country ORDER BY Name")
$result = mysqli_store_result($link, "find what is this")
Always make the query in an if statement or use error message.
if ($result = mysqli_query($link, "SELECT Code, Name FROM Country ORDER BY Name")) {
$row_cnt = mysqli_num_rows($result);
output
Result set has 239 rows.
$data[$i] = mysqli_fetch_all($result);
mysqli_free_result($result);
Returns an associative array that corresponds to the fetched row or NULL if there are no more rows.
if ($result = mysqli_query($link, $query)) {
/* fetch associative array */
while ($row = mysqli_fetch_assoc($result)) {
printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);
}
/* free result set */
mysqli_free_result($result);
}
Arvada (USA)
Cape Coral (USA)
Output
Result set has 5 fields.
Returns the number of rows affected by the last INSERT, UPDATE, REPLACE or DELETE query.
mysqli_affected_rows ( mysqli $link ) : int
Affected rows (UPDATE): 168
Affected rows (DELETE): 815
Queries which do not fall into one of the preceding formats are not supported. In these situations, mysqli_info() will return an empty string.
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
mysqli_query($link, "CREATE TEMPORARY TABLE t1 LIKE City");
/* INSERT INTO .. SELECT */
mysqli_query($link, "INSERT INTO t1 SELECT * FROM City ORDER BY ID LIMIT 150");
printf("%s\n", mysqli_info($link));
/* close connection */
mysqli_close($link);