What are some potential pitfalls of using mysql_fetch_array in PHP and how can they be avoided?

One potential pitfall of using mysql_fetch_array 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 mysqli_fetch_array or PDO instead.

// Using mysqli_fetch_array
$result = mysqli_query($conn, $query);
while ($row = mysqli_fetch_array($result)) {
    // Process the data
}

// Using PDO
$stmt = $pdo->query($query);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    // Process the data
}