What are some best practices for handling multiple search terms in a PHP PDO query?

When handling multiple search terms in a PHP PDO query, it's important to properly sanitize and bind the parameters to prevent SQL injection attacks. One approach is to dynamically build the query string based on the number of search terms provided, using placeholders for each term and binding them to the query. This allows for flexibility in handling any number of search terms while maintaining security.

// Assuming $searchTerms is an array of search terms
$placeholders = array_fill(0, count($searchTerms), '?');
$placeholders = implode(', ', $placeholders);

$query = "SELECT * FROM table WHERE column IN ($placeholders)";
$statement = $pdo->prepare($query);

foreach ($searchTerms as $key => $term) {
    $statement->bindValue($key + 1, $term);
}

$statement->execute();
$results = $statement->fetchAll();