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:

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


will replace :id with the value of $id

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




    // $username contains the username of the current row


do you mean

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

Cheers! :)