What are the potential security risks of using mysql_real_escape_string in PHP?

Using mysql_real_escape_string in PHP can still leave your application vulnerable to SQL injection attacks if not used properly. It is recommended to use parameterized queries or prepared statements with PDO or MySQLi instead, as they provide a more secure way to interact with the database and prevent SQL injection attacks.

// Using PDO with parameterized queries 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();