0

在 PDO 我有功能

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

我不想使用 PDO 函数,我使用 Yii 框架,所以我想在 Yii 中做这个语句,

我需要帮助如何编写语句和获取部分,我尝试这样的事情:

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

但不工作,任何人帮助,请,干杯。

4

2 回答 2

2
$result = Yii::app()->db->createCommand()
->select('*')
->from($this->tabName)
->where('paymentID = '. $val)
->queryAll();
于 2013-10-29T11:22:48.727 回答
-1

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)).

于 2013-10-29T12:18:19.540 回答