我使用下面的代码来搜索全文索引
$query = $this->Posts->find() ->contain(['Categories' ]) ->where([ 'MATCH(Posts.title) AGAINST(? IN BOOLEAN MODE)' => $search ]);
但我得到了以下错误
SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters
请
提前告知,
谢谢!
尝试将您的查询重写为:
$query = $this->Posts->find() ->contain(['Categories']) ->where([ "MATCH(Posts.title) AGAINST(:search IN BOOLEAN MODE)" ]) ->bind(':search', $search);
确保安装了最新的CakePHP 3.x版本,因为这是很久以前添加的.
以下内容可行,但请注意,它会使您的代码容易受到SQL注入攻击:
// 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)" ]);