Zend_Db_Select LIKE clause
How can I set this query
SELECT city_id FROM cities WHERE city开发者_运维百科_name LIKE "%Vicenza%"
using the Zend_Db_Select class?
Since @Jerec's answer didn't mention it... in order to have the effect of:
LIKE '%{$searchTerm}%'
You'll need to add the extra modifiers to the variable like such:
// Correct way
->where("city_name LIKE ?", "%{$searchTerm}%")
// Wrong ways
->where("city_name LIKE %?%", $searchTerm)
->where("city_name LIKE '%?%'", $searchTerm)
Might seem obvious, but took me three attempts to get it right.
You could use this method
$select = $dbTable->select()
->from('cities', 'city_id')
->where('city_name LIKE ?', $searchTerm);
where $dbTable is an instance of an Zend_Db_Table class
精彩评论