Duplicate data in response to a query

Asked

Viewed 40 times

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

1 answer

1


It is only showing the value of the items by the Key and Index of each one, it is not duplicated, or you use the Keys or the indexes to access the values

Browser other questions tagged

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