0

我想在 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

4

2 回答 2

4

你也可以试试这个

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

$model = new Project;
$models = $model->findAll($criteria);
于 2013-01-28T11:21:15.393 回答
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);
于 2013-01-26T20:22:38.393 回答