我想在 Yii 框架中将此 SQL 查询转换为 CDbCriteria 格式,以便在 Yii 中使用它:
SELECT title FROM project WHERE ((title like 'to %') or (title like ' % to %') or (title like '% to'));
Yiiframework CDbCriteria 描述链接如下:
我想在 Yii 框架中将此 SQL 查询转换为 CDbCriteria 格式,以便在 Yii 中使用它:
SELECT title FROM project WHERE ((title like 'to %') or (title like ' % to %') or (title like '% to'));
Yiiframework CDbCriteria 描述链接如下:
你也可以试试这个
$criteria = new CDbCriteria;
$criteria->select = "title";
$criteria->compare('title',' to ',true);
$model = new Project;
$models = $model->findAll($criteria);
干得好:
$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);