fetchassociative

I’m new to yii and trying to fetch and associative array with queryall() method. After reading up on it it seems like it should be the default but not working by me. Can abyone help?

Greatly appreciated.

Here is some code tested on a real project of mine:




 $sql = "SELECT * FROM common_attributes_locale WHERE category_id=:category_id";

 $categoryId = 1;

 $command = Yii::app()->db->createCommand($sql);

 $command->bindParam("category_id", $categoryId, PDO::PARAM_INT);

 $rows = $command->queryAll();



This returns what a mysql_fetch_assoc would return on a mysql db.

To see the returned value so that you can parse it try a print_r.

Here’s my result:




print_r($rows);


Array ( 

    [0] => Array ( [category_id] => 1 [culture_id] => 1 [name] => Company [description] => 'A company') 

    [1] => Array ( [category_id] => 1 [culture_id] => 2 [name] => Entreprise  [description] => 'Une Entreprise' ) 

) 



I can now parse it very easily and print the name attribute as it is indeed an associative array:




foreach($rows as $currentRow) {

   echo $currentRow['name'];

}



Thankx. Exactly what I needed explained.

Much clearer than anything i could’ve read.