What are the potential pitfalls of using custom functions in SQL queries in PHP?

The potential pitfalls of using custom functions in SQL queries in PHP include vulnerability to SQL injection attacks and decreased performance due to the need for additional processing. To mitigate these risks, it is recommended to use prepared statements with parameterized queries instead of directly embedding custom functions in SQL queries.

// Using prepared statements with parameterized queries to avoid SQL injection attacks and improve performance
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$stmt->bindParam(':username', $username);
$stmt->execute();