1

I would like Yii2's Query Builder to return empty strings for null values.

The equivalent of this:

IFNULL(Table.Column1, '')

In this:

$rows = (new \yii\db\Query())
->select(['Column1', 'Column2'])
->from('Table')
->all();
1
  • Please try the suggested answers and then mark them. Commented Jul 14, 2016 at 7:36

2 Answers 2

2

Try this

$rows = (new \yii\db\Query())
->select(['Column1'=>'IFNULL(Column1,''), 'Column2'])
->from('Table')
->all();
Sign up to request clarification or add additional context in comments.

Comments

1

You can use this way

You can specify columns to be selected in either an array or a string, like the following. http://www.yiiframework.com/doc-2.0/yii-db-query.html#select()-detail

$rows = (new \yii\db\Query())
   ->select([" IFNULL(Column1,''),  Column2  "])
   ->from('Table')
   ->all();

or

$rows = (new \yii\db\Query())
   ->select([" IFNULL(Column1,'')",  Column2])
   ->from('Table')
   ->all();

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.