What are the best practices for conducting searches in PHP using AND, OR, and NOT operators?

When conducting searches in PHP using AND, OR, and NOT operators, it is important to properly structure the query to ensure accurate results. This can be achieved by using parentheses to group conditions, using the logical operators (&&, ||, !) appropriately, and utilizing the SQL query language effectively.

// Example of conducting a search query with AND, OR, and NOT operators
$searchTerm = 'example';
$condition1 = 'condition1';
$condition2 = 'condition2';

$query = "SELECT * FROM table_name WHERE (column1 LIKE '%$searchTerm%' OR column2 LIKE '%$searchTerm%') AND column3 = '$condition1' AND column4 != '$condition2'";

// Execute the query using mysqli_query or PDO