How can functions be properly integrated into SQL queries in PHP to avoid errors?

When integrating functions into SQL queries in PHP, it is important to properly escape and sanitize user input to prevent SQL injection attacks and errors. One way to do this is by using prepared statements with parameterized queries, which separate the SQL query from the user input. This helps to ensure that the input is treated as data and not executable code.

// Example of using prepared statements to integrate functions into SQL queries safely
$pdo = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password');
$stmt = $pdo->prepare('SELECT * FROM users WHERE email = :email');
$stmt->bindParam(':email', $email);
$stmt->execute();
$results = $stmt->fetchAll();