MATCH AGAINST in Doctrine

2019-05-22 02:39发布

问题:

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].'*');