Cdbcommand->Where Needs Associative Array?

This is my first project using Yii, and I’m really happy with it so far.

I’m building up a query using the Query Builder syntax, and I’m getting an “Invalid argument supplied for foreach()” when I add a ->where() command.

Here’s the code that’s generating the error:




$ccList = array(871210, 871230, 871260, 871310, 871330, 871350, 871370);


$reader=$connection->createCommand()

   ->select('rc_code', 'start_date', 'completion_date', 'percentage', 'est_value', 'cost_to_date', 'program_code')

   ->from('rpt_bac_status_vw')

   ->where('in', 'rc_code', $ccList)

   ->query();



I’m getting the error from the where clause, on the foreach loop. It’s telling me I’m giving an invalid argument.




CDbCommand.php(781)


public function where($conditions, $params=array())

{

   $this->_query['where']=$this->processConditions($conditions);

 

   foreach($params as $name=>$value)

      $this->params[$name]=$value;

   return $this;

}



So do I need to declare $ccList as an associative array? According to the docs I’m using the proper syntax for the IN field.

Any help or suggestions would be greatly appreciated.

[color="#006400"]/* Moved from "Bug Discussions" to "General Discussion for Yii 1.1.x" */[/color]

Hi Tomcdona, welcome to the forum.

The right syntax is:




   where(array('in', 'rc_code', $ccList))



http://www.yiiframework.com/doc/api/1.1/CDbCommand#setWhere-detail

Thanks Softark, I read that wrong.

Sorry for the confusion, and thanks for the quick response!