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

Using deprecated mysql_ functions in PHP scripts can lead to security vulnerabilities, as these functions are no longer maintained and may not be secure against SQL injection attacks. Additionally, using deprecated functions can make your code less future-proof, as they may be removed in future versions of PHP. It is recommended to switch to mysqli or PDO for database interactions to ensure better security and compatibility.

// Connect to MySQL using mysqli instead of mysql_
$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 = "example";
$stmt->execute();
$result = $stmt->get_result();

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

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