How can the SQL query in the PHP code be optimized to handle partial search terms effectively?

To optimize the SQL query in the PHP code to handle partial search terms effectively, you can use the LIKE operator in the SQL query along with the '%' wildcard character to match any sequence of characters. This allows you to search for partial terms within the database. Additionally, you can sanitize user input to prevent SQL injection attacks.

$searchTerm = $_POST['searchTerm']; // Assuming search term is submitted via POST

// Sanitize the search term to prevent SQL injection
$searchTerm = mysqli_real_escape_string($conn, $searchTerm);

$sql = "SELECT * FROM table_name WHERE column_name LIKE '%$searchTerm%'";
$result = mysqli_query($conn, $sql);

if(mysqli_num_rows($result) > 0) {
    while($row = mysqli_fetch_assoc($result)) {
        // Output search results
    }
} else {
    echo "No results found.";
}