I try to execute a simple query like this:
$tot = Yii::app()->db->createCommand()
->select('sum(field)')
->from('products')
->where('id = ' . $id)
->queryRow();
But $tot return me null value.
I think you need to add an alias to your sum, so something like this might work:
$tot = Yii::app()->db->createCommand()
->select('sum(field) as mySum')
->from('products')
->where('id = ' . $id)
->queryRow();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With