CI_DB_query_builder::_wh PHP Method

_wh() protected method

WHERE, HAVING
protected _wh ( string $qb_key, mixed $key, mixed $value = NULL, string $type = 'AND ', boolean $escape = NULL ) : CI_DB_query_builder
$qb_key string 'qb_where' or 'qb_having'
$key mixed
$value mixed
$type string
$escape boolean
return CI_DB_query_builder
    protected function _wh($qb_key, $key, $value = NULL, $type = 'AND ', $escape = NULL)
    {
        $qb_cache_key = $qb_key === 'qb_having' ? 'qb_cache_having' : 'qb_cache_where';
        if (!is_array($key)) {
            $key = array($key => $value);
        }
        // If the escape value was not set will base it on the global setting
        is_bool($escape) or $escape = $this->_protect_identifiers;
        foreach ($key as $k => $v) {
            $prefix = count($this->{$qb_key}) === 0 && count($this->{$qb_cache_key}) === 0 ? $this->_group_get_type('') : $this->_group_get_type($type);
            if ($v !== NULL) {
                if ($escape === TRUE) {
                    $v = ' ' . $this->escape($v);
                }
                if (!$this->_has_operator($k)) {
                    $k .= ' = ';
                }
            } elseif (!$this->_has_operator($k)) {
                // value appears not to have been set, assign the test to IS NULL
                $k .= ' IS NULL';
            } elseif (preg_match('/\\s*(!?=|<>|IS(?:\\s+NOT)?)\\s*$/i', $k, $match, PREG_OFFSET_CAPTURE)) {
                $k = substr($k, 0, $match[0][1]) . ($match[1][0] === '=' ? ' IS NULL' : ' IS NOT NULL');
            }
            $this->{$qb_key}[] = array('condition' => $prefix . $k . $v, 'escape' => $escape);
            if ($this->qb_caching === TRUE) {
                $this->{$qb_cache_key}[] = array('condition' => $prefix . $k . $v, 'escape' => $escape);
                $this->qb_cache_exists[] = substr($qb_key, 3);
            }
        }
        return $this;
    }