How can the mysqli_fetch_row function be used effectively in PHP to retrieve data from SQL queries?
The mysqli_fetch_row function can be used effectively in PHP to retrieve data from SQL queries by fetching the next row from a result set as an enumerated array. This function returns an array where each element corresponds to a column in the result set. To use mysqli_fetch_row, you need to first establish a connection to the database, execute a query, and then loop through the result set using mysqli_fetch_row to fetch each row.
// Establish a connection to the database
$connection = mysqli_connect("localhost", "username", "password", "database");
// Execute a query
$query = "SELECT * FROM table";
$result = mysqli_query($connection, $query);
// Loop through the result set and fetch rows using mysqli_fetch_row
while ($row = mysqli_fetch_row($result)) {
// Process each row
print_r($row);
}
// Close the connection
mysqli_close($connection);