What potential pitfalls are there when using the mysql_query function in PHP?

One potential 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 to interact with MySQL databases for better security and functionality.

// Example using mysqli instead of mysql_query
$mysqli = new mysqli("localhost", "username", "password", "database");

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

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

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "ID: " . $row["id"] . " - Name: " . $row["name"] . "<br>";
    }
} else {
    echo "0 results";
}

$mysqli->close();