find()->select() function not working

Hey guys I have a couple troubles with find()->select()…

Fist problem…I cant selct just de culumns I need.

I have this variable:

$sql=‘select anio_id, SUM(ene) as enero,sum(feb)as febrero, sum(mar) as marzo,sum(abr) as abril, sum(may) as mayo, sum(jun) as junio, sum(jul) as julio, sum(ago) as agosto,sum(sep) as septiembre, sum(oct) as octubre, sum(nov) as noviembre, sum(dic) as diciembre from seisp.incidencia where municipio_id=:munchen and anio_id>2 group by anio_id asc’;

then this code:

$in = \app\models\Incidencia::findBySql($sql,[’:munchen’=>$val])->select([‘ene’, ‘feb’, ‘mar’])->asArray()->all();

in order to select function I was supposed to get…

Array (

[0] => Array (

  [enero] => 2 [febrero] => 2 [marzo] => 2 ) 

[1] => Array (

  [enero] => 5 [febrero] => 2 [marzo] => 0 ) 

[2] => Array (

  [enero] => 3 [febrero] => 4 [marzo] => 3 ) 

[3] => Array (

  [enero] => 7 [febrero] => 9 [marzo] => 2 ) ) 

I already tried ->select([‘enero’, ‘febrero’, ‘marzo’]) instead of select([‘ene’, ‘feb’, ‘mar’]) but

I always get the full array which is

Array (

[0] => Array (

[anio_id] => 3 [enero] => 2 [febrero] => 2 [marzo] => 2 [abril] => 4 [mayo] => 4 [junio] => 1 [julio] => 5 [agosto] => 3 [septiembre] => 1 [octubre] => 1 [noviembre] => 3 [diciembre] => 5 ) [1] => Array ( [anio_id] => 4 [enero] => 5 [febrero] => 2 [marzo] => 0 [abril] => 3 [mayo] => 4 [junio] => 3 [julio] => 0 [agosto] => 0 [septiembre] => 3 [octubre] => 1 [noviembre] => 0 [diciembre] => 4 )

and the second problem is how to make a bidimentional array into a single one…

Array (

[0] => Array (

  [enero] => 2 [febrero] => 2 [marzo] => 2 ) 

[1] => Array (

  [enero] => 5 [febrero] => 2 [marzo] => 0 ) 

[2] => Array (

  [enero] => 3 [febrero] => 4 [marzo] => 3 ) 

[3] => Array (

  [enero] => 7 [febrero] => 9 [marzo] => 2 ) )

into…

Array ( [enero] => 2 [febrero] => 2 [marzo] => 2 )

Array ( [enero] => 5 [febrero] => 2 [marzo] => 0 )

Array ( [enero] => 3 [febrero] => 4 [marzo] => 3 )

Array ([enero] => 7 [febrero] => 9 [marzo] => 2 )

thnks

findBySql()->select() won’t work. It’s by design.

Please look at the API reference of yii\db\ActiveRecord::findBySql().

http://www.yiiframework.com/doc-2.0/yii-db-activerecord.html#findBySql()-detail