2012-12-06 3 views
0

CDbCriteria 및 CActiveDataProvider를 사용하여이 쿼리를 어떻게 실행할 수 있습니까?Cdbcriteria를 사용한 Custome 쿼리

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

업데이트 : 가 마침내 나는이 쓴 :

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

을하지만 내가 가진 오류 :

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

확실하지 당신이 함께 할 것입니다, 절을 비교 사용해보십시오 ' x 님의 주문 ':

<?php 
$criteria = new CDbCriteria; 
$criteria->compare('title', $title, true); 
$criteria->order = 'title DESC'; 
$dp = new CActiveDataprovider('posts', array(
    'criteria' => $criteria 
)); 
+0

감사하지만 도움을주지 못함 –

0

이것은 다음과 같이 얻을 수있다 :

$dataProvider=new CActiveDataProvider('tbl_post', array(
    'criteria'=>array(
    'condition'=>'title LIKE % '.$title.' %', 
    'order'=>'title DESC', 
    ), 
    )); 

    $dataProvider->getData(); 

도 참조 : Help

감사합니다.

관련 문제