What are the benefits of using mysql_fetch_assoc over mysql_fetch_row in PHP?

When fetching data from a MySQL database in PHP, using mysql_fetch_assoc over mysql_fetch_row provides the benefit of returning an associative array where the keys are column names, making it easier to access and manipulate data. This can result in cleaner and more readable code, as you can directly access specific columns by their names instead of numerical indices.

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

// Query database
$result = mysqli_query($conn, "SELECT * FROM table");

// Fetch data as an associative array
while ($row = mysqli_fetch_assoc($result)) {
    echo $row['column_name'];
}

// Close connection
mysqli_close($conn);