Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to select from Query\Builder with LIKE %something% ?

Having Query\Builder and assigning dynamically parameters, I can't seem to figure out how to do LIKE selects.

// Loop params and assign them to query builder
$iteration = 0;
foreach($params as $param => $paramValue) {
            if ($iteration == 0) {
                $function = 'where';
            } else {
                $function = 'andWhere';
            }

            $equalitySign = ($equal == 'LIKE' ? '%' : '');
            $resultSet->$function($param . ' ' . $equal . ' :' . $param . ':', array($param => ($equalitySign . $paramValue . $equalitySign)));

            $iteration++;
}

This doesn't work.



2.5k
Accepted
answer

I'm currently doing this:

$querybuilder->where("column1 LIKE CONCAT('%', ?0, '%')", array($value));

This works too:

$querybuilder->where('name LIKE ?0', array("%{$name}%"));