CI_DB_query_builder::_like PHP Method

_like() protected method

Internal LIKE
protected _like ( mixed $field, string $match = '', string $type = 'AND ', string $side = 'both', string $not = '', boolean $escape = NULL ) : CI_DB_query_builder
$field mixed
$match string
$type string
$side string
$not string
$escape boolean
return CI_DB_query_builder
    protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '', $escape = NULL)
    {
        if (!is_array($field)) {
            $field = array($field => $match);
        }
        is_bool($escape) or $escape = $this->_protect_identifiers;
        // lowercase $side in case somebody writes e.g. 'BEFORE' instead of 'before' (doh)
        $side = strtolower($side);
        foreach ($field as $k => $v) {
            $prefix = count($this->qb_where) === 0 && count($this->qb_cache_where) === 0 ? $this->_group_get_type('') : $this->_group_get_type($type);
            if ($escape === TRUE) {
                $v = $this->escape_like_str($v);
            }
            if ($side === 'none') {
                $like_statement = "{$prefix} {$k} {$not} LIKE '{$v}'";
            } elseif ($side === 'before') {
                $like_statement = "{$prefix} {$k} {$not} LIKE '%{$v}'";
            } elseif ($side === 'after') {
                $like_statement = "{$prefix} {$k} {$not} LIKE '{$v}%'";
            } else {
                $like_statement = "{$prefix} {$k} {$not} LIKE '%{$v}%'";
            }
            // some platforms require an escape sequence definition for LIKE wildcards
            if ($escape === TRUE && $this->_like_escape_str !== '') {
                $like_statement .= sprintf($this->_like_escape_str, $this->_like_escape_chr);
            }
            $this->qb_where[] = array('condition' => $like_statement, 'escape' => $escape);
            if ($this->qb_caching === TRUE) {
                $this->qb_cache_where[] = array('condition' => $like_statement, 'escape' => $escape);
                $this->qb_cache_exists[] = 'where';
            }
        }
        return $this;
    }