Get Number Of Fields

How can i get number of fields with Yii. lets say mysql_num_fields equivalent.

$cmd = Yii::app()->db->createCommand($query);

$res = $cmd->queryAll();

$nb=mysql_num_fields($res);

thanks

If you check what queryAll() returns - http://www.yiiframework.com/doc/api/1.1/CDbCommand#queryAll-detail

you will see that $res is an array that contains all the rows of the query result where each row in turn is an array of fields… or an empty array if there is no query result

So with


count($res[0]);

you would get the number of fields in the first row… of course you need to first check that $res is not an empty array.

that is exactly what i’ve done.