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();



If you check what queryAll() returns -

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


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.