0

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;

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.