yii\db\QueryBuilder::buildSimpleCondition PHP Method

buildSimpleCondition() public method

Creates an SQL expressions like "column" operator value.
public buildSimpleCondition ( string $operator, array $operands, array &$params ) : string
$operator string the operator to use. Anything could be used e.g. `>`, `<=`, etc.
$operands array contains two column names.
$params array the binding parameters to be populated
return string the generated SQL expression
    public function buildSimpleCondition($operator, $operands, &$params)
    {
        if (count($operands) !== 2) {
            throw new InvalidParamException("Operator '{$operator}' requires two operands.");
        }
        list($column, $value) = $operands;
        if (strpos($column, '(') === false) {
            $column = $this->db->quoteColumnName($column);
        }
        if ($value === null) {
            return "{$column} {$operator} NULL";
        } elseif ($value instanceof Expression) {
            foreach ($value->params as $n => $v) {
                $params[$n] = $v;
            }
            return "{$column} {$operator} {$value->expression}";
        } elseif ($value instanceof Query) {
            list($sql, $params) = $this->build($value, $params);
            return "{$column} {$operator} ({$sql})";
        } else {
            $phName = self::PARAM_PREFIX . count($params);
            $params[$phName] = $value;
            return "{$column} {$operator} {$phName}";
        }
    }