SELECT with JOIN return an Object with Internal List

0

I would like to know if it is possible to do a select with join where the second table table will return more than one row and in that create an object with an inner list. To get clearer, see the example:

Tabela Usuario: idUsuario, nome, cpf
Tabela Veiculos: idVeiculo, nome, placa, dono

select: select u.nome, v.placa from Usuario u JOIN Veiculos v ON v.dono = u.idUsuario;

resultado:
joao, kkk-0000
joao, jjj-0000
paulo, iii-9999
paulo, yyy-9999

In PDO I use the PDO :: FETCH_CLASS command and I get the following Object.

Query object:

obj[0] = joao, kkk-0000
obj[1] = joao, jjj-0000
obj[2] = paulo, iii-9999
obj[3] = paulo, yyy-9999 

I would like to receive this:

obj[0] = joao, array(kkk-0000,jjj-0000)
obj[1] = paulo, array(iii-9999, yyy-9999) 
    
asked by anonymous 06.11.2014 / 22:05

1 answer

0

If you use:

$Ps->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP);

You'll get:

array(2) {
    ["joao"]=>
        array(2) {
            [0]=>
            string(8) "kkk-0000"
            [1]=>
            string(8) "jjj-0000"
        }
    ["paulo"]=>
        array(2) {
            [0]=>
            string(8) "iii-9999"
            [1]=>
            string(8) "yyy-9999"
        }
}

I can not test now, but maybe with the other fetch modes you can also get one object instead of an array.

    
06.11.2014 / 22:55