How can the use of mysql_fetch_assoc() impact the retrieval of data in PHP?

Using mysql_fetch_assoc() in PHP can impact the retrieval of data by returning an associative array where the keys are column names from the result set. This can make it easier to access specific columns by name rather than index. To use mysql_fetch_assoc() effectively, you need to ensure that the MySQL extension is enabled in PHP and that you are connected to a MySQL database.

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

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

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

// Close connection
mysqli_close($conn);