how to pass query result to variable

Good Day,

I have this problem in how to get each data result and pass it into my model attributes. my query is like this.


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

$query = $command->select('*')->from('tbl_user')->where('id=:id',array(':id'=>$id))->queryAll();

     

i think bindColumn is the one i need but i cant get exactly how to code it. is there a way like

 (1st column result) = $this->var1;

hope someone can help :)

Thanks! :D

I think this is what you are searching for:

http://www.yiiframework.com/doc/guide/1.1/en/database.dao#binding-columns

can you post the code here?

or or how can i set the :id to my variable $id?

$sql="SELECT username, email FROM tbl_user WHERE id=:id";

Ok, I am a bit confused now. Do you want to bind a variable to your "where" statement (like in your last post) or do you want to bind the columns of your result to variables like you said in your first post? There is a difference




$command->bindParam(":id",$id,PDO::PARAM_STR);



will replace :id with the value of $id

if you want to bind the resulting columns to variables you would use something like that.




$response=$command->query()->bindColumn(1,$username);

while($response->read()!==false)

{

    // $username contains the username of the current row

}



do you mean http://www.yiiframework.com/doc/api/1.1/CActiveRecord#populateRecord-detail

haha sorry for the inconsistency of my posts. :) but thanks! you answered both of my questions!!

Cheers! :)