在Yii中PDO获取函数重写

In PDO i have function

$st = $this->db->query('SELECT * FROM ' . $this->tabName . ' WHERE paymentID= ' . $val);
if ($st == NULL){
return 2;
}     
$result = $st->fetch();
    if ($result == NULL) {
    return 1;
} else {
return 0;
}

i don't want to use PDO functions, I use Yii framework, so i want to do this statement in Yii,

I need help how to write statement and fetch part, i try something like this:

$st = CGWOrder::model()->findAll(array('condition'=> "paymentID=$val"));
if ($st == NULL){
return 2;
}
foreach($st as $index=>$value){}
if ($value == NULL){
return 1;
}else {
return 0;
}

but not working, anybody help, pls, cheers.

$result = Yii::app()->db->createCommand()
->select('*')
->from($this->tabName)
->where('paymentID = '. $val)
->queryAll();

CActiveRecord->findAll() behaves similarly to find() which means either use CDbCriteria to specify the conditions or write the operation as CGWOrder::model()->findAll('paymentID = :val', array(':val' => $val)).