Yii Framework Forum: Custome Query With Cdbcriteria - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Custome Query With Cdbcriteria Rate Topic: -----

#1 User is offline   Arash26 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 113
  • Joined: 08-October 12

Posted 06 December 2012 - 01:40 PM

Guys,

How can I execute this query with CDbCriteria and CActiveDataProvider?

'SELECT * FROM tbl_post where title LIKE %'.$title.'% ORDER BY title LIKE '.$title.' DESC , title LIKE '.$title.'% DESC'

0

#2 User is offline   Arash26 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 113
  • Joined: 08-October 12

Posted 06 December 2012 - 05:07 PM

I finally wrote this:

$criteria = new CDbCriteria;
                        $criteria->addCondition('title LIKE :title');                        
                        $criteria->params = array(':title'=>'%'.$title.'%',':t1'=>$title,':t2'=>$title.'%');;
                        $criteria->order='title LIKE :t1 DESC , title LIKE :t2 DESC';


but got this error:
CDbCommand failed to execute the SQL statement: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens. The SQL statement executed was: SELECT COUNT(*) FROM `tbl_post` `t` WHERE title LIKE :title

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users