PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

LIKE conditions with Zend_Db_Select

Note: This article was originally published at Planet PHP on 18 August 2010.
Planet PHP

Despite all the implications of using LIKE in MySQL, sometimes it's quite useful for a proof-of-concept to be able to use it.

Even though this is a rather trivial example, I hope it will be of help to whoever is wondering how to use a LIKE in a where using a Zend_Db_Select::where() or Zend_Db_Select::orWhere() and did not manage to find decent documentation about it.

As you can see, we bind a parameter to the where() method using the ? symbol, then when assigning the value of this parameter - second parameter - we append the wildcard character %. The new binded parameter value is then string% and which gets quoted and executed giving you the expected output.