Specify condition(s) in the where clause of a query
Note: this function works with key / value, or a
passed array with key / value pairs

@param mixed $key
@param mixed $val
@param mixed $escape
@return QueryBuilderInterface
174861
public function where($key, $val=[], $escape=NULL): QueryBuilderInterface
	{
		return $this->_whereString($key, $val);
	}
1046439
public function addSelectOption($key, $val)
    {
        if (!is_string($key)) {
            throw new InvalidArgumentException(
                'Setting key must be a string.'
            );
        }

        // Make sure default options are loaded.
        if ($this->selectOptions === null) {
            $this->selectOptions();
        }

        $this->selectOptions[$key] = $val;

        return $this;
    }
1065337
public function orWhereIn(string $key, array $values): QueryBuilder
    {
        $this->addWhere($key, 'IN', $values, 'OR');
        return $this;
    }
1268270
public function where($key, $operator = null, $value = null)
    {
        return $this->filter($this->operatorForWhere(...func_get_args()));
    }
873174
function (key, val) {
    if ( key.indexOf( '[]' ) !== -1 ) {
      key = key.replace( '[]', '' );

      if (isArray(this.queryParams[key])) {
        this.queryParams[key].push(val);
      }
      else {
        this.queryParams[key] = [val];
      }
    }
    else {
      this.queryParams[key] = val;
    }
  }
1374831
public function whereIn(string $key, array $values): QueryBuilder
    {
        $this->addWhere($key, 'IN', $values, 'AND');
        return $this;
    }
32007
public function orWhere(string $key, string $operator, $value): QueryBuilder
    {
        $this->addWhere($key, $operator, $value, 'OR');
        return $this;
    }
1346529
public function where($key, $condition)
    {
        $this->conditions[$key] = self::$conditionRegex[$condition];
        return $this;
    }
853795
public function where($key, $operator = null, $value = null): IQueryBuilderHandler
    {
        // If two params are given then assume operator is =
        if (\func_num_args() === 2) {
            $value = $operator;
            $operator = '=';
        }

        if (\is_bool($value) === true) {
            $value = (int)$value;
        }

        return $this->whereHandler($key, $operator, $value);
    }
1144920
public function setDefaultData($key, $val = null)
    {
        if(is_array($key))
        {
            foreach($key as $k=>$v)
            {
                $this->setDefaultData($k, $v);
            }
        }
        else
        {
            $this->defaultData[$key] = $val;
        }

        return $this;
    }
770993
protected function _validate($key, $val)
    {
        // try each rule function
        foreach ($this->rules as $rule => $is_true) {
            if ($is_true) {
                $function = $this->functions[$rule];
                $args = $this->arguments[$rule]; // Arguments of rule

                $valid = true;
                if(is_array($val)) {
                    foreach($val as $v) {
                        $valid = $valid && (empty($args)) ? $function($v) : $function($v, $args);
                    }
                } else {
                    $valid = (empty($args)) ? $function($val) : $function($val, $args);
                }

                if ($valid === FALSE) {
                    $this->registerError($rule, $key);

                    $this->rules = array();  // reset rules
                    $this->filters = array();
                    return FALSE;
                }
            }
        }

        $this->validData[$key] = $val;
        return TRUE;
    }
820620
public function where($key, $operator = null, $value = null)
    {
        // If two params are given then assume operator is =
        if (func_num_args() == 2) {
            $value = $operator;
            $operator = '=';
        }
        return $this->whereHandler($key, $operator, $value);
    }
804265
public function query($name, $val = null) {
        return isset($this->_queries[$name]) ?
                    $this->_queries[$name] :
                    $val;
    }
59419
public WhereCondition Val(Object val) {

        if ("?".equals(val)) {
            // question mark means WILDCARD for prepared statement
            mSgSQL.append(" ?");
        }
        else {
            mSgSQL.append("'");
            mSgSQL.append(val.toString());
            mSgSQL.append("'");
        }

        checkTokenOrderIsCorrect(ESqlToken.VALUE);
        return WhereCondition.this;
    }
491682
protected function textarea($key, $val)
    {
        $value = null;
        $value = isset($val['value']) ? $val['value'] : '' ;
        unset($val['value']);

        $extra = ['type'  => 'textarea', 'value' => $value];

        return $this->composeElement($key, $val, $extra);
    }
879409
protected function _where($key, $val=[]): array
	{
		$where = [];
		$pairs = [];

		if (is_scalar($key))
		{
			$pairs[$key] = $val;
		}
		else
		{
			$pairs = $key;
		}

		foreach($pairs as $k => $v)
		{
			$where[$k] = $v;
			$this->state->appendWhereValues($v);
		}

		return $where;
	}
308917
protected function parseWhereItem($key, $val)
    {
        $hasAlias = $this->query->hasAlias();
        
        $key = $this->formatKey($key, $hasAlias);
        $whereStr = '';
        
        if(is_array($val)) {                                    // 1 值是数组形式 'name'=>[ ]
            if (isset($val[1]) && is_string($val[0])) {                  // 1.1 值是数组，且第一个元素为字串，则解析为操作符 'name'=>['operator', 'name']
                $exp	=	strtolower($val[0]);
                if (preg_match('/^(eq|neq|gt|egt|lt|elt|<>|>|<|>=|<=|=)$/', $exp)) {          // 比较运算 'name'=>['>=', 'value']
                    $_val = $this->formatValue($val[1]);
                    if (is_null($_val)) {
                        $whereStr .= $key . (($exp === '=' || $exp === 'eq') ? ' IS NULL' : ' IS NOT NULL');
                    } else {
                        $whereStr .= $key . ' '. static::$operators[$exp] . ' ' . $_val;
                    }
                } elseif (preg_match('/^(not\s*like|like)$/', $exp)){               // 模糊查找 'name'=>['like', 'value'], value 支持空格分隔的OR查询
                    
                    if (!is_numeric($val[1]) && is_string($val[1])) {
                        $val[1] = preg_split('/\s+/', $val[1]);
                    }
                    
                    if (is_array($val[1])) {
                        $likeLogic  =   isset($val[2]) ? strtoupper($val[2]) : null;
                        if(!$likeLogic || !in_array($likeLogic, array('AND','OR','XOR'))){
                            $likeLogic = 'OR';
                        }
                        $like       =   array();
                        foreach ($val[1] as $item){
                            if (!$item) continue;
                            
                            $item   = trim($item, '%');
                            $like[] = $key . ' ' . static::$operators[$exp] . ' ' . $this->formatValue('%' . $item . '%');
                        }
                        if ($like) {
                            $whereStr .= '(' . implode(' ' . $likeLogic . ' ', $like) . ')';
                        }
                    } else {
                        $val[1]   = trim($val[1], '%');
                        $whereStr .= $key . ' ' . static::$operators[$exp] . ' ' . $this->formatValue('%' . $val[1] . '%');
                    }
                    
                } elseif ('bind' == $exp ){                                         // 使用绑定     'name' => ['bind', 'value']
                    $whereStr .= $key . ' = :' . $val[1];
                } elseif ('exp' == $exp ){                                          // 使用表达式 'name' => ['exp', 'value']
                    $whereStr .= $key . ' ' . $val[1];
                } elseif (preg_match('/^(notin|not in|in)$/', $exp)){               // IN 运算    'name' => ['in', 'value']
                    if (isset($val[2]) && 'exp' == $val[2]) {                       // IN 运算1: 'name' => ['in', 'value', 'exp']
                    	$whereStr .= $key.' '. static::$operators[$exp].' '.$val[1];
                    } elseif (is_string($val[1]) && strpos($val[1], 'select')) {    // IN 运算2: 'name' => ['in', 'select....'] 子查询
                        if (strpos($val[1], '(') === false) {
                            $val[1] = '(' . $val[1] . ')';
                        }
                        $whereStr .= $key . ' ' . static::$operators[$exp] . $val[1];
                    } else {                                                        // IN 运算2: 'name' => ['in', 'value']
                        if (is_string($val[1])) {
                            $val[1] =  explode(',', $val[1]);
                        }
                        $zone      =   implode(',', $this->formatValue($val[1]));
                        $whereStr .= $key . ' ' . static::$operators[$exp] . ' (' . $zone.')';
                    }
                } elseif (preg_match('/^(notbetween|not between|between)$/', $exp)){ // BETWEEN运算 'name'=>['between', 'value1,value2']
                    $data = is_string($val[1]) ? explode(',', $val[1]) : $val[1];
                    $whereStr .=  $key.' '. static::$operators[$exp].' '.$this->formatValue($data[0]).' AND '.$this->formatValue($data[1]);
                }else{
                    throw new DbException(sprintf('database query parse error, not allowed expression : \'%s\' .', $val[0]));
                }
            } else {                                        // 1.2 值是数组，且第一个元素不是字串 'name' => [['like', 'aaa], ['=', 'bbb'], 'and']
                $count = count($val);
                $rule  = isset($val[$count-1]) ? (is_array($val[$count-1]) ? strtoupper($val[$count-1][0]) : strtoupper($val[$count-1]) ) : '' ;
                if($rule && in_array($rule, array('AND','OR','XOR'))) {
                    $count  = $count -1;
                }else{
                    $rule   = 'AND';
                }
                for($i=0; $i<$count; $i++) {
                    $whereStr .= $this->parseWhereItem($key, $val[$i]).' '.$rule.' ';
                }
                $whereStr = '(' . substr($whereStr,0,-4) . ')';
            }
        } else {                                         // 2 值是字串，['name'=>'xxxx'] 进行 Like 匹配或 =,或进行参数绑定
            $likeFields   =   array();   //$this->config['db_like_fields'];  // 限定可进行like的字段，暂时不取
            if($likeFields && preg_match('/^('.$likeFields.')$/i',$key)) {        // 键为已配置的可查询字段组
                $val = trim($val, '%');
                $whereStr   = $key.' LIKE '.$this->formatValue('%'.$val.'%');
            }else {
                $_val = $this->formatValue($val);
                if (is_null($_val)) {
                    $whereStr .= $key . ' IS NULL';
                } else {
                    $whereStr   = $key . ' = ' . $_val;
                }
            }
        }
        
        return $whereStr;
    }