2015-10-19 65 views
0

我已经调用了一个函数。获取表号(结果= 0)结果并更新相同的表值0到1.我正在使用更新query.i已运行此函数返回错误::缺少CDbCommand :: update()参数2。Yii foreach错误?

public function newdisplaycontent() 
{ 
    $count = Yii::app()->db->createCommand() 
     ->select() 
     ->from('scrolltable') 
     ->where('result=:result', array(':result'=>0)) 
     ->queryAll(); 
$rs=array(); 
//print_r($count); 

foreach($count as $item){ 
//process each item here 
    $rs=$item['ID']; 
    $user=Yii::app()->db->createCommand() 
    ->update("scrolltable SET result = 1") 
    ->where('ID=:id', array(':id'=>$rs)); 
} 

return $rs; 
} 

感谢您的功能帮助..

回答

3

update()正确的语法会像下面:

$user=Yii::app()->db->createCommand() 
->update("scrolltable",array("result" => "1")) 
->where('ID=:id', array(':id'=>$rs)); 

由于正式文件:

update()创建并执行更新SQL语句。该方法将正确地转义列名并绑定要更新的值。

public integer update(string $table, array $columns, mixed $conditions='', array $params=array ()) 
+0

感谢它的工作正常 – Kannan