Zend db picks as wildcards

tried to find some information about "like" in selects with zend db but had no success. The problem is that it is not clear how to use the wildcard '%' next to the LIKE clause

Bad idea that I used initially and that is recommended in hundreds of places on the net is

 $db->select()
    ->where('text LIKE "%'.$query.'%"');

      

I guess the correct answer would be something like this:

 $db->select()
    ->where('text LIKE ?', $query);

      

but no wildcards are used

I've tried several solutions, but they all don't work:

$db->select()
    ->where('text LIKE ?', '%$query%');
$db->select()
    ->where('text LIKE ?', '%{$query}%');

      

Can anyone point to the documentation or provide a good solution for this?

The second argument to the where () method is optional. This is the value to be replaced in the expression. Zend_Db_Select quotes the value and replaces it with the question mark ("?") Character in the expression.

insufficiently informs

+3


source to share


1 answer


The% character must be part of the variable associated with the request. Your second example will work if you used double quotes instead of single quotes. Thus, you can:

$query = '%'.$query.'%';
$db->select()
   ->where('text LIKE ?', $query);

      



or

$db->select()
   ->where('text LIKE ?', "%$query%");

      

+17


source







All Articles