What are the common pitfalls when using mysql_query function in PHP?

One common pitfall when using the mysql_query function in PHP is that it is deprecated as of PHP 5.5.0 and removed in PHP 7.0.0. It is recommended to use mysqli or PDO instead for database operations to ensure compatibility and security.

// Using mysqli instead of mysql_query
$connection = mysqli_connect("localhost", "username", "password", "database");

$query = "SELECT * FROM table";
$result = mysqli_query($connection, $query);

if ($result) {
    while ($row = mysqli_fetch_assoc($result)) {
        // Process the data
    }
} else {
    echo "Error: " . mysqli_error($connection);
}

mysqli_close($connection);