PDO eliminates duplicate SQL fields

0

Good luck, I'm using PDO to run my querys .

SQL:

SELECT Pessoa.IdPessoa, Pessoa.IdPessoa, Pessoa.Nome AS 'Nome', Pessoa.DataNascimento AS 'Nascimento' FROM Pessoa WHERE Pessoa.EstadoCivil = '1'

When I run this sql for example, which brings the IdPessoa field twice, return the PDO using the

$result->fetchAll(PDO::FETCH_ASSOC);

Ignore one of the results and the query brings an array, but only with a IdPessoa

[0] => Array
        (
            [IdPessoa] => 7
            [Nome] => Carlos Alberto Martins Barros
            [Nascimento] =>
        )
)

Is there anything to be done, so that the PDO does not eliminate this duplicity?

If you only use

$result->fetchAll();

It will bring duplicate results, but all fields with numeric indexes and indexes with the result name of Query will not work.

    
asked by anonymous 08.05.2018 / 22:52

1 answer

0

Use:

$result->fetchAll(\PDO::FETCH_CLASS);

or

$result->fetchAll(\PDO::FETCH_ASSOC);

Any questions see this two PHP documentation

PDOStatement :: fetchAll

PDOStatement :: fetch

This documentation will further detail the options you have. But I believe the examples above will suffice.

    
08.05.2018 / 23:09