What are the potential pitfalls of using the mysql_fetch_array function in PHP for SQL queries?

Potential pitfalls of using the mysql_fetch_array function in PHP for SQL queries include vulnerability to SQL injection attacks and deprecated usage of the mysql extension (which has been removed in PHP 7). To address these issues, it is recommended to use parameterized queries with prepared statements and utilize the mysqli or PDO extensions for database interactions.

// Connect to the database using mysqli
$mysqli = new mysqli("localhost", "username", "password", "database");

// Prepare a parameterized query
$stmt = $mysqli->prepare("SELECT * FROM table WHERE column = ?");
$stmt->bind_param("s", $value);

// Execute the query
$stmt->execute();

// Bind the result to variables
$stmt->bind_result($col1, $col2);

// Fetch the results
while ($stmt->fetch()) {
    // Process the results
}

// Close the statement and connection
$stmt->close();
$mysqli->close();