What are some potential pitfalls to avoid when using mysql_fetch_assoc in PHP to retrieve data from a database?

One potential pitfall to avoid when using mysql_fetch_assoc in PHP is not checking for false or NULL values returned when fetching data. This can lead to errors or unexpected behavior in your code. To avoid this issue, always check if the result of mysql_fetch_assoc is not false before using the fetched data.

$result = mysql_query("SELECT * FROM table");
if($result){
    while($row = mysql_fetch_assoc($result)){
        // Process fetched data here
    }
} else {
    echo "Error fetching data from database.";
}