Create command query

Hi guys!! I need some help for a query.

My db query is:

“SELECT Titolo FROM bibliografie WHERE MATCH(Titolo) AGAINST(’ ’ IN NATURAL LANGUAGE MODE)”

I want to create the query in my search model. I try this:

$rows = (new \yii\db\Query())
->select(‘Titolo’)
->from(‘bibliografie’)
->where(‘MATCH(Titolo) AGAINST("" IN NATURAL LANGUAGE MODE)’)
->all();

 $command = $query->createCommand();
 $rows = $command->queryAll();

But the result it’s wrong. Really, nothing happened. Which is the right way?

Thank you very much!!!

You had to avoid field escaping using \yii\db\Expression:

$rows = (new \yii\db\Query())
->select(‘Titolo’)
->from(‘bibliografie’)
->where( new \yii\db\Expression(‘MATCH(Titolo) AGAINST("" IN NATURAL LANGUAGE MODE)’) )
->all();

Doc here: https://www.yiiframework.com/doc/api/2.0/yii-db-expression

Thank you. I think this is the right way, but it give me a syntax error just here:

->where( new \yii\db\Expression(‘MATCH(Titolo) AGAINST("" IN NATURAL LANGUAGE MODE)’) )

ERROR: syntax error, unexpected ‘AGAINST’ (T_STRING), expecting ‘,’ or ‘)’

You are using wrong " ’ " char.

 $rows = (new \yii\db\Query())
->select('Titolo')
->from('bibliografie')
->where( new \yii\db\Expression('MATCH(Titolo) AGAINST("" IN NATURAL LANGUAGE MODE)') )
->all();

Now it’s ok, thank you very much!!!