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

Using outdated PHP functions like mysql_query can pose security risks as they are deprecated and no longer supported. It is recommended to use modern functions like mysqli or PDO for database interactions to prevent SQL injection attacks and ensure compatibility with newer PHP versions.

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

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

// Perform a query using prepared statements
$stmt = $mysqli->prepare("SELECT * FROM table WHERE column = ?");
$stmt->bind_param("s", $value);
$value = "example";
$stmt->execute();
$result = $stmt->get_result();

// Fetch results
while ($row = $result->fetch_assoc()) {
    // Process the data
}

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