What are the potential pitfalls of using outdated PHP functions like mysql_db_query in a script?

Using outdated PHP functions like mysql_db_query can pose security risks as they are deprecated and no longer supported in newer PHP versions. It is recommended to use modern functions like mysqli or PDO for database queries to ensure compatibility and security.

// Connect to the database using mysqli
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Perform a query using mysqli
$sql = "SELECT * FROM table";
$result = $conn->query($sql);

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

$conn->close();