将MySql查询转换为yii框架查询系统

时间:2013-01-26 18:33:01

标签: php mysql yii

我想在Yii框架中将此SQL查询转换为CDbCriteria格式,以便我可以在Yii中使用它:

SELECT title FROM project WHERE ((title like 'to %') or (title like ' % to %') or (title like '% to'));

Yiiframework CDbCriteria描述链接如下:

http://www.yiiframework.com/doc/api/1.1/CDbCriteria

2 个答案:

答案 0 :(得分:4)

你也可以尝试这个

$criteria = new CDbCriteria;
$criteria->select = "title";
$criteria->compare('title',' to ',true);

$model = new Project;
$models = $model->findAll($criteria);

答案 1 :(得分:2)

你走了:

$criteria = new CDbCriteria;
$criteria->select = "title";
$criteria->condition = "((title like ':to%') or (title like ' % :to %') or (title like '% :to'))";
$criteria->params = array(':to' => 'to');

$model = new Project;
$models = $model->findAll($criteria);