I am using mySQL full text search and the column "nimi" is indexed accordingly.
An hardcoded query, which injects the search term directly into SQL, is working properly:
...
$term = '+mysearch*';
$result = DB::table('register')
->select(['nimi', 'kood'])
->selectRaw("MATCH(nimi) AGAINST ('" . $term . "' IN BOOLEAN MODE) AS score")
->having('score', '>', 0)
->orderBy('score', 'desc')
->get();
...
However, when I try to do the same with the array binding, the query is not working:
$result = DB::table('register')
->select(['nimi', 'kood'])
->selectRaw('MATCH(nimi) AGAINST ("?" IN BOOLEAN MODE) AS score', [$term])
// or
// ->selectRaw('MATCH(nimi) AGAINST (":TEST" IN BOOLEAN MODE) AS score', ['TEST' => $term])
// or without quotes
// ->selectRaw('MATCH(nimi) AGAINST (? IN BOOLEAN MODE) AS score', [$term])
->having('score', '>', 0)
->orderBy('score', 'desc')
->get();
The last query searches for ? (or for :TEST), not for $term.
How to get it working? $term is entered by users and I don't want to use hardcoded version because of possibility of SQL injection attack.