1 query.inc | public DatabaseCondition::condition($field, $value = NULL, $operator = NULL) |
Helper function: builds the most common conditional clauses.
This method can take a variable number of parameters. If called with two parameters, they are taken as $field and $value with $operator having a value of IN if $value is an array and = otherwise.
Do not use this method to test for NULL values. Instead, use QueryConditionInterface::isNull() or QueryConditionInterface::isNotNull().
Parameters
string $field: The name of the field to check. If you would like to add a more complex condition involving operators or functions, use where().
mixed $value: The value to test the field against. In most cases, this is a scalar. For more complex options, it is an array. The meaning of each element in the array is dependent on the $operator.
string|null $operator: The comparison operator, such as =, <, or >=. It also accepts more complex options such as IN, LIKE, or BETWEEN. Defaults to IN if $value is an array, and = otherwise.
Return value
QueryConditionInterface: The called object.
Overrides QueryConditionInterface::condition
See also
QueryConditionInterface::isNull()
QueryConditionInterface::isNotNull()
File
- core/
includes/ database/ query.inc, line 1773 - Non-specific Database query code. Used by all engines.
Class
- DatabaseCondition
- Generic class for a series of conditions in a query.
Code
public function condition($field, $value = NULL, $operator = NULL) {
if (!isset($operator)) {
if (is_array($value)) {
$operator = 'IN';
}
else {
$operator = '=';
}
}
$this->conditions[] = array(
'field' => $field,
'value' => $value,
'operator' => $operator,
);
$this->changed = TRUE;
return $this;
}