0
That is the code :
$conn = new PDO('mysql:host=localhost;dbname=locadora','root','');
$resul = $conn->query("SELECT * FROM usuario");
echo "<pre>";
$resul = $resul->fetchAll();
?>
And the way out is like this :
array(2) {
[0]=>
array(8) {
["id"]=>
string(1) "1"
[0]=>
string(1) "1"
["id_cli"]=>
string(1) "1"
[1]=>
string(1) "1"
["user"]=>
string(12) "david.santos"
[2]=>
string(12) "david.santos"
["senha"]=>
string(60) "I82A1G"
[3]=>
string(60) "I82A1G"
}
[1]=>
array(8) {
["id"]=>
string(1) "2"
[0]=>
string(1) "2"
["id_cli"]=>
string(1) "2"
[1]=>
string(1) "2"
["user"]=>
string(12) "joao.batista"
[2]=>
string(12) "joao.batista"
["senha"]=>
string(6) "senha"
[3]=>
string(6) "senha"
}
}
The question is, why are the data duplicated? I know if you use "fetch(PDO::FETCH_ASSOC)" the problem will be solved, but I would like to understand why this is happening