繁体   English   中英

Phalcon 1.3.0使用Phalcon \\ Mvc \\ Model \\ Query来制作LIKE子句

[英]Phalcon 1.3.0 using Phalcon\Mvc\Model\Query to make LIKE clause

我正在尝试使用绑定参数使用Phalcon \\ Mvc \\ Model \\ Query制作LIKE '%something%'

有什么想法怎么做?

这不适合我:

$robots = Robots::query()
->where("type LIKE :type:")
->andWhere("year < 2000")
->bind(array("type" => "mechanical"))
->order("name")
->execute();

试试下面的代码。 我使用类似的代码,最后只有最后一个'%'。

$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();

我不确定这是否是这样做的目的(看起来有点hackish)但它的确有效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM