What are the potential pitfalls of using the mysql_fetch_assoc function in PHP when retrieving data from a MySQL database?

The potential pitfall of using the mysql_fetch_assoc function in PHP is that it is deprecated as of PHP 5.5.0 and removed in PHP 7.0.0. To avoid this issue, you should use the mysqli_fetch_assoc function instead, which is the improved version of mysql_fetch_assoc.

<?php
// Connect to database
$mysqli = new mysqli("localhost", "username", "password", "database");

// Check connection
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
}

// Query database
$result = $mysqli->query("SELECT * FROM table");

// Fetch data using mysqli_fetch_assoc
while ($row = $result->fetch_assoc()) {
    // Process data
    echo $row['column_name'] . "<br>";
}

// Close connection
$mysqli->close();
?>