What are some potential pitfalls when using the mysql_real_escape_string function in PHP?

One potential pitfall when using the mysql_real_escape_string function in PHP is that it is deprecated as of PHP 5.5.0 and removed in PHP 7.0.0. Therefore, it is recommended to use parameterized queries with prepared statements using PDO or MySQLi instead to prevent SQL injection attacks.

// Using parameterized queries with PDO to prevent SQL injection
$pdo = new PDO("mysql:host=localhost;dbname=mydatabase", "username", "password");

$stmt = $pdo->prepare("INSERT INTO users (username, password) VALUES (:username, :password)");
$stmt->bindParam(':username', $username);
$stmt->bindParam(':password', $password);

$username = "example_user";
$password = "example_password";

$stmt->execute();