yu_er2008
(Yangfutao2000)
1
when i use CDbCommand to create a sql ,i get this error message,the code like this
$criteria = Yii::app()->db->createCommand()
->from($this->tableName);
$criteria->where(array('or' , 'u.name like \'%:key%\'' , 'u.real_name like \'%:key%\'') , array(':key'=>$keyword));
when i get the sql by $criteria->text,i found the sql is all right ,anyone can help me ?
and i found its no erro if i remove the second paramters
Keith
(Kburton)
2
Your parameter place holder is inside a string, so the DB engine doesn’t recognise it. Try something like this instead:
$criteria->where(array('or' ,
"u.name LIKE CONCAT('%', :key, '%')",
"u.real_name LIKE CONCAT('%', :key, '%')"
), array(':key'=>$keyword));
yu_er2008
(Yangfutao2000)
3
good , you are right ,thank you very much !