How can the "LIKE" operator be utilized in PHP for search functionality?

When implementing search functionality in PHP, the "LIKE" operator can be utilized to search for specific patterns within a database. This operator allows for wildcard characters such as "%" to be used in the search query, enabling more flexible and dynamic search capabilities. By using the "LIKE" operator, you can search for partial matches or patterns within a column of a database table.

// Example of using the LIKE operator for search functionality
$searchTerm = $_GET['search']; // Get the search term from the user input

// Prepare and execute a SQL query using the LIKE operator
$sql = "SELECT * FROM products WHERE product_name LIKE '%" . $searchTerm . "%'";
$result = mysqli_query($conn, $sql);

// Display the search results
while($row = mysqli_fetch_assoc($result)) {
    echo $row['product_name'] . "<br>";
}