我想在yii框架中创建一个sql查询,如下所示:
mysql> SELECT id, body, MATCH (title,body) AGAINST
-> ('Security implications of running MySQL as root') AS score
-> FROM articles WHERE MATCH (title,body) AGAINST
-> ('Security implications of running MySQL as root');
我试过了,但不起作用:
$dataProvider = new CActiveDataProvider('data', array(
'criteria'=>array(
'condition' => 'MATCH (title,body) AGAINST ('Security implications of running MySQL as root') AS score',
WHERE MATCH (title,body) AGAINST ('Security implications of running MySQL as root')
'limit' => '20', ),
'pagination' => false
));
http://www.yiiframework.com/doc/api/1.1/CDbCriteria#condition-详细
这是指SQL语句中的WHERE子句
所以应该只有MATCH (title,body) AGAINST ('Security implications of running MySQL as root')
http://www.yiiframework.com/doc/api/1.1/CDbCriteria#select-详细
这是指SQL语句中的SELECT子句
这是id, body, MATCH (title,body) AGAINST ('Security implications of running MySQL as root') AS score
的位置
首先需要执行搜索列的ALTER查询。
ALTER TABLE item ADD FULLTEXT(title,description,location);
查询以搜索
$query = commonmodelsItem::find()
->where(['is_active'=>'1']);
$query->andWhere("MATCH(title,description,location) AGAINST
('$searchKeywords' IN BOOLEAN MODE)");