What are the potential risks of using outdated PHP functions like mysql_real_escape_string?

Using outdated PHP functions like mysql_real_escape_string can pose security risks as they are no longer recommended for use in modern PHP versions. These functions may not provide adequate protection against SQL injection attacks, leaving your application vulnerable to malicious attacks. To mitigate this risk, it is recommended to use parameterized queries with PDO or MySQLi extensions for secure data handling.

// Example of using parameterized queries with PDO to prevent SQL injection
$pdo = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password');
$stmt = $pdo->prepare('SELECT * FROM users WHERE username = :username');
$stmt->bindParam(':username', $username);
$stmt->execute();
$results = $stmt->fetchAll();