【问题标题】:Phalcon 1.3.0 using Phalcon\Mvc\Model\Query to make LIKE clausePhalcon 1.3.0 使用 Phalcon\Mvc\Model\Query 制作 LIKE 子句
【发布时间】:2014-07-10 04:43:23
【问题描述】:

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

有什么办法吗?

这对我不起作用:

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

【问题讨论】:

    标签: php phalcon


    【解决方案1】:

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

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

    我不确定这是否是有意的方式(看起来有点老套),但它确实有效。

    【讨论】:

      猜你喜欢
      • 2013-09-27
      • 1970-01-01
      • 2013-06-18
      • 2016-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多