What is the purpose of using mysql_real_escape_string in PHP and what potential issues can arise from its usage?

When dealing with user input in PHP, it is important to sanitize the data to prevent SQL injection attacks. One common method to achieve this is by using the mysql_real_escape_string function, which escapes special characters in a string to make it safe for use in a SQL query. However, it is important to note that this function is deprecated as of PHP 5.5.0 and removed in PHP 7.0.0, so it is recommended to use prepared statements with parameterized queries instead.

// Deprecated method using mysql_real_escape_string
$user_input = $_POST['user_input'];
$escaped_input = mysql_real_escape_string($user_input);
$query = "SELECT * FROM users WHERE username='$escaped_input'";
$result = mysql_query($query);
```

To solve this issue using prepared statements:

```php
// Recommended method using prepared statements
$user_input = $_POST['user_input'];
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$stmt->bindParam(':username', $user_input);
$stmt->execute();