How can the use of the LIKE operator in SQL queries be optimized to prevent potential security vulnerabilities in PHP applications?

When using the LIKE operator in SQL queries in PHP applications, it is important to properly sanitize user input to prevent SQL injection attacks. 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 prevent malicious input from being executed as SQL code.

// Sanitize user input before using it in a SQL query
$searchTerm = $_GET['searchTerm']; // Assuming searchTerm is from user input

// Prepare a SQL query using a parameterized query with a LIKE clause
$stmt = $pdo->prepare("SELECT * FROM table_name WHERE column_name LIKE ?");
$stmt->execute(["%$searchTerm%"]);

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