Reputation: 145
I used the below code to search using full-text indexes
$query = $this->Posts->find()
->contain(['Categories' ])
->where([
'MATCH(Posts.title) AGAINST(? IN BOOLEAN MODE)' => $search
]);
But I got the below error
SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters
Please advise
Thanks in advance!
Upvotes: 2
Views: 1619
Reputation: 4469
Try rewriting your query as:
$query = $this->Posts->find()
->contain(['Categories'])
->where([
"MATCH(Posts.title) AGAINST(:search IN BOOLEAN MODE)"
])
->bind(':search', $search);
Make sure you have the latest CakePHP 3.x version installed, as this was added no so long ago.
The following will work, but be warned it makes your code vulnerable to SQL injection attacks:
// for educational purposes only. Don't use in production environments
$query = $this->Posts->find()
->contain(['Categories'])
->where([
"MATCH(Posts.title) AGAINST('{$search}' IN BOOLEAN MODE)"
]);
Upvotes: 6