开发者

Zend_Db_Select LIKE clause

开发者 https://www.devze.com 2023-03-27 05:43 出处:网络
How can I set this query SELECT city_id FROM cities WHERE city开发者_运维百科_name LIKE \"%Vicenza%\"

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

0

精彩评论

暂无评论...
验证码 换一张
取 消