In PHP, what is the advantage of using mysqli_fetch_assoc() over fetch_row() when fetching data from a database?

When fetching data from a database in PHP, using mysqli_fetch_assoc() is advantageous over fetch_row() because it returns an associative array where the keys are the column names, making it easier to access the data by column name rather than index. This can improve code readability and maintainability, especially when dealing with large datasets or complex queries.

// Connect to database
$connection = mysqli_connect("localhost", "username", "password", "database");

// Query to fetch data
$query = "SELECT * FROM table";
$result = mysqli_query($connection, $query);

// Fetch data using mysqli_fetch_assoc()
while ($row = mysqli_fetch_assoc($result)) {
    // Access data by column name
    echo $row['column_name'];
}

// Close connection
mysqli_close($connection);