What are the potential pitfalls of using outdated mysql_ functions in PHP?

Using outdated mysql_ functions in PHP can lead to security vulnerabilities as these functions are deprecated and no longer receive updates. It is recommended to switch to mysqli or PDO for database operations to ensure better security and 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 users WHERE username = ?");
$stmt->bind_param("s", $username);
$username = "john_doe";
$stmt->execute();
$result = $stmt->get_result();

// Fetch data
while ($row = $result->fetch_assoc()) {
    echo $row['username'] . "<br>";
}

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