What is the potential issue with escaping characters in SQL queries when using PHP?

When escaping characters in SQL queries using PHP, the potential issue is that it leaves the code vulnerable to SQL injection attacks if not done properly. To solve this issue, it is recommended to use prepared statements with parameterized queries instead of manually escaping characters.

// Establish a database connection
$pdo = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password');

// Prepare a SQL query using a parameterized query
$stmt = $pdo->prepare('SELECT * FROM users WHERE username = :username');

// Bind the parameter value
$stmt->bindParam(':username', $username);

// Execute the query
$stmt->execute();

// Fetch the results
$results = $stmt->fetchAll();