MATCH AGAINST in Doctrine

橙三吉。 提交于 2019-12-08 02:29:21

问题


I found that if I use MATCH AGAINST in Doctrine with WHERE syntax does not replace the parameters passed. For example if I run the following code $

q = Doctrine_Query::create()
    ->select('*')
    ->from('TourismUnit tu')
    ->where('FALSE');
if ($keywords) {
    $keywords_array = $this->parse_keywords($keywords);
    for ($i = 0; $i < sizeof($keywords_array); $i++)
        $q->orWhere("MATCH (name, description) AGAINST ('?*' IN BOOLEAN MODE)", $keywords_array[$i]);
}

does not find any results. And if they use the string concatenation seems to work.

 $q->orWhere("MATCH (name, description) AGAINST ('".$keywords_array[$i]."*' IN BOOLEAN MODE)");

I use Doctrine 1.2.2.

Does anyone know why not replace the parameters before executing the sql expression?


回答1:


the use of single quote causing the problem,
convert it to use concat("'", ?, "*'")




回答2:


In prepared statements as above, the placeholder doesn't like quotes as shown in the doctrine manual.

So you could simply write:

$q->orWhere("MATCH (name, description) AGAINST (? IN BOOLEAN MODE)", $keywords_array[$i].'*');


来源:https://stackoverflow.com/questions/4238814/match-against-in-doctrine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!