PDO eliminates SQL field duplicity

Asked

Viewed 35 times

0

Good guys, 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 field IdPessoa twice, the PDO return using the function

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

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

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

has something to be done, so that the PDO does not eliminate this duplicity?

only use

$result->fetchAll();

It will bring duplicate results, but it will be all fields, with numeric indexes and indexes named after the Query, so it wouldn’t serve.

  • Puts aliases in the second column.

  • I have a similar problem, but it is not in select. It is the Insert that causes this, because every record sent is duplicated in the table.

1 answer

0

Utilize:

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

or

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

Any questions see these two PHP documentations

Pdostatement::fetchAll

Pdostatement:fetch:fetch

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.