How can outdated MySQL functions in PHP pose a security risk to a web application?

Outdated MySQL functions in PHP can pose a security risk to a web application because they may be vulnerable to SQL injection attacks. To mitigate this risk, it is recommended to use parameterized queries or prepared statements with MySQLi or PDO instead of the outdated MySQL functions.

// Using prepared statements with MySQLi
$mysqli = new mysqli("localhost", "username", "password", "dbname");

$stmt = $mysqli->prepare("SELECT * FROM users WHERE username = ?");
$stmt->bind_param("s", $username);

$username = "example";
$stmt->execute();

$result = $stmt->get_result();

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

$stmt->close();
$mysqli->close();