簡體   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