Yii queryBuilder; If dbexpression is not being quoted well

I have this query :


 $query->select('if(bud.posa=2,1,0) AS proprietaire,if(bud.du=1 and bud.gog=1,1,0) as pa')->from('bud');

if I execute it is giving synthax error; I try to echo the sql that is being generated I found that it is not being generated(quoting problem) well, here is what is generated:


select if(bud.posa=2, `1`, `0)` AS `proprietaire`, if(bud.du=1 and bud.gog=1, `1`, `0)` AS `pa` FROM `bud`




`0)`

is what is causing the error ,I don’t see how to solve it,Any solution?

Please refer to the API documentation of yii\db\Query::select().

http://www.yiiframework.com/doc-2.0/yii-db-query.html

In your case,




if(bud.posa=2,1,0) AS proprietaire,if(bud.du=1 and bud.gog=1,1,0) as pa



is considered to be a plain string and devided by commas into the following 6 columns.




if(bud.posa=2,

1,

0) AS proprietaire,

if(bud.du=1 and bud.gog=1,

1,

0) as pa



Probably you could write something like this:




$query->select([

    'proprietair' => new Expression('if(bud.posa=2,1,0)'),

    'pa' => new Expression('if(bud.du=1 and bud.gog=1,1,0)'),

])->from('bud');