[英]Phalcon 1.3.0 using Phalcon\Mvc\Model\Query to make LIKE clause
I'm trying to make LIKE '%something%'
with Phalcon\\Mvc\\Model\\Query with bound parameters. 我正在尝试使用绑定参数使用Phalcon \\ Mvc \\ Model \\ Query制作
LIKE '%something%'
。
Any ideas how to do it? 有什么想法怎么做?
This didn't work for me: 这不适合我:
$robots = Robots::query()
->where("type LIKE :type:")
->andWhere("year < 2000")
->bind(array("type" => "mechanical"))
->order("name")
->execute();
Try below code. 试试下面的代码。 I'm using similar code with only last '%' on the end.
我使用类似的代码,最后只有最后一个'%'。
$robots = Robots::query()
->where("type LIKE :type:")
->andWhere("year < 2000")
// Just add the '%' where you need them:
->bind(array("type" => "%mechanical%"))
->order("name")
->execute();
// OR
$searchTerm = "mechanical";
$robots = Robots::query()
->where("type LIKE :type:")
->andWhere("year < 2000")
->bind(array("type" => "%" . $searchTerm ."%"))
->order("name")
->execute();
I'm not sure if this is intended way of doing this (looks little bit hackish) but it works. 我不确定这是否是这样做的目的(看起来有点hackish)但它的确有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.