What are the best practices for handling and processing search queries with multiple keywords in PHP and MySQL?

When handling search queries with multiple keywords in PHP and MySQL, it is important to properly sanitize and escape the input to prevent SQL injection attacks. One common approach is to split the search query into individual keywords, construct a dynamic SQL query using placeholders for each keyword, and then execute the query using prepared statements.

// Assuming $searchQuery contains the input search query
$keywords = explode(" ", $searchQuery);
$placeholders = array_fill(0, count($keywords), "?");
$placeholders = implode(", ", $placeholders);

$sql = "SELECT * FROM table_name WHERE column_name IN ($placeholders)";
$stmt = $pdo->prepare($sql);

$stmt->execute($keywords);
$results = $stmt->fetchAll();