Shazery Nasir
Shazery Nasir

Reputation: 281

getting value from yii query builder

How can i extract the value that has been taken from database through yii's query builder? below is my code

$value = Yii::app()->db->createCommand()
        ->select('sum(totalPoints) as pointsSum')
        ->from('fndn_UserTotal')
        ->where('userId =:id', array(':id'=>$userId))
        //->where('userId = ' . $userId)
        ->queryRow();

right now, i'm outputting it inside a log in my backend, here is the code.

error_log(print_r($value, true), 3, 'debug.log'); 

the output will be inside an array. how can i get just the pointSum ? i tried using $value->pointsSum in the above code but it doesnt work.

i want to do something like, echo pointSum;

Upvotes: 0

Views: 797

Answers (2)

sakhunzai
sakhunzai

Reputation: 14490

if you have installed Xdebug try this :

ob_start();
xdebug_var_dump($value);
$dump = ob_get_contents();
ob_end_clean();
error_log($dump,3, 'debug.log'); 

Event if you do not have

ob_start();
var_dump($value);
$dump = ob_get_contents();
ob_end_clean();
error_log($dump,3, 'debug.log'); 

I am not sure about this line: error_log($dump,3, 'debug.log'); and its arguments

Upvotes: 0

Developerium
Developerium

Reputation: 7265

queryRow will return "the first row (in terms of an array) of the query result, false if no result."

you can var_dump($value); to see exactly what is in there!

if it has any value, it's as an array, like:

$value['pointsSum'];

http://www.yiiframework.com/doc/api/1.1/CDbCommand#queryRow-detail

Upvotes: 1

Related Questions