matlab2020
matlab2020

Reputation: 3

convert MySql Query to yii framework Query system

I want to convert this SQL query to CDbCriteria format in Yii framework so I can use it in Yii:

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

Yiiframework CDbCriteria Description Link is as below:

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

Upvotes: 0

Views: 645

Answers (2)

amirmohammad
amirmohammad

Reputation: 374

also you can try this

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

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

Upvotes: 4

schmunk
schmunk

Reputation: 4708

Here you go:

$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);

Upvotes: 2

Related Questions