Gdn_SQLDriver::like PHP Method

like() public method

Adds to the $this->_Wheres collection. Used to generate the LIKE portion of a query. Called by $this->Like(), $this->NotLike()
public like ( mixed $Field, string $Match = '', string $Side = 'both', string $Op = 'like' ) : Gdn_SQLDriver
$Field mixed The field name (or array of field name => match values) to search in for a like $Match.
$Match string The value to try to match using a like statement in $Field.
$Side string A string indicating which side of the match to place asterisk operators. Accepted values are left, right, both, none. Default is both.
$Op string Either 'like' or 'not like' clause.
return Gdn_SQLDriver $this
    public function like($Field, $Match = '', $Side = 'both', $Op = 'like')
    {
        if (!is_array($Field)) {
            $Field = array($Field => $Match);
        }
        foreach ($Field as $SubField => $SubValue) {
            $SubField .= ' ' . $Op . ' ';
            switch ($Side) {
                case 'left':
                    $SubValue = '%' . $SubValue;
                    break;
                case 'right':
                    $SubValue .= '%';
                    break;
                case 'both':
                    if (strlen($Match) == 0) {
                        $SubValue = '%';
                    } else {
                        $SubValue = '%' . $SubValue . '%';
                    }
                    break;
            }
            $Expr = $this->conditionExpr($SubField, $SubValue);
            $this->_where($Expr);
        }
        return $this;
    }