For the first question, you’re using the wrong method. The addInCondition() method is used to compare a column (or expression) against several values, so it expects you to provide an array.
First, when fetching data from the $_GET array, use the methods Yii provides, as they will prevent errors if the requested key doesn’t exist:
$id = Yii::app()->request->getQuery('id');
If ‘id’ is your primary key field, you can get the record without using a CDbCriteria object like this:
$model = YourArClass::model()->findByPk($id);
If it’s not your primary key field, you can use this:
If you need to use a CDbCriteria object because you have additional conditions that you have to apply, use this form:
$criteria->addColumnCondition(array('id'=>$id));
All of the above examples will safely parameterize the generated query, so they will be safe from SQL injection.
The example code in your second question is wide open to SQL injection. Look into using the addSearchCondition() method when you need to use a LIKE clause. You’ll need to call that method twice, and set the $operator parameter to ‘OR’ for the second one, but watch out for operator precedence issues if you’re combining it with other conditions.
$criteria=new CDbCriteria;
$criteria->addCondition("t.status='1'");
$criteria->addCondition("title LIKE '%".$keywords."%' OR description LIKE '%".$keywords."%'");
$criteria->addInCondition('t.id',$_GET['id']);
The Query:
WHERE (((t.status='1') AND (title LIKE '%keywords%' OR description LIKE '%keywords%')) AND (t.id IN (:ycp1, :ycp2)))