I searched for a solution free of database abstraction but I didn’t find execute() method.
It works , of course , but it is ignored as I add WHERE condition and this error is occurred:
The entire query is this:
$query->addSelect("MATCH(title,tag) AGAINST (':query_search' IN NATURAL LANGUAGE MODE) AS score")
->where('status=:status_published OR status=:status_finished AND reliable = 1',
':status_published' => Poll::STATUS_PUBLISHED
->addParams([':query_search' => $q ])
I tried to put all params in addParams() including those are in where() but it didn’t make any difference.
Invalid parameter number: number of bound variables does not match number of tokens
The SQL being executed was: SELECT MATCH(title, tag) AGAINST (''someSearchQuery'' IN NATURAL LANGUAGE MODE) AS score FROM `poll` WHERE status=1 OR status=3 AND reliable = 1 ORDER BY `score` DESC LIMIT 20
The error is about parameters and binding, isn’t it? As I know, it happens when number of parameters is not equal to number of bound values. When I remove the where() method from query everything start working again whether totalCount is there or not.
Well, I write here possible solutions for future visitors.
There is no way to bind some parameters to yii\db\Query::select() via addParams() and bind some other parameters in where() simultaneously for ActiveDataProvider because params of addParams() is ignored for some reason. All blends of addParams() and where()was tested.
What can we do?
Code like those days in elementary school and insert user input into database query. For example:
$query->select("* , MATCH(title) AGAINST (’$userQuery’ IN NATURAL LANGUAGE MODE) AS score")
Do not user where() while you need to bind parameters to select()
Feel free and implement whole active query process and data provider proccess from scratch.