What are the potential security risks associated with using mysql_real_escape_string in PHP code?

Using `mysql_real_escape_string` in PHP code can potentially lead to security risks such as SQL injection attacks if not used properly. It is recommended to use parameterized queries or prepared statements with PDO or MySQLi instead to prevent SQL injection vulnerabilities. These methods automatically handle escaping and sanitizing user input, making the code more secure.

// Using prepared statements 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();