PHP Using PHP with MySQL Querying the Database with PHP Retrieving the Result Set

James Barrett
James Barrett
13,252 Points

Why does the array return the same value twice?

array(1) { [0]=> array(16) { ["U_ID"]=> string(1) "1" [0]=> string(1) "1" ["U_Forename"]=> string(5) "James" [1]=> string(5) "James" ["U_Surname"]=> string(7) "Barrett" [2]=> string(7) "Barrett" ["U_Email"]=> string(25) "james-barrett@hotmail.com" [3]=> string(25) "james-barrett@hotmail.com" ["U_Password"]=> string(8) "password" [4]=> string(8) "password" ["U_Team"]=> string(7) "Arsenal" [5]=> string(7) "Arsenal" ["U_Biography"]=> string(19) "Hi there I am James" [6]=> string(19) "Hi there I am James" ["U_Activated"]=> string(1) "1" [7]=> string(1) "1" } }

I am working on my own project and the fetchAll() returns an array of the result. However why is it two-dimensional and why is it returning the same value twice?

Thanks, James.

James Barrett
James Barrett
13,252 Points

Apologies for formatting of the code... I did indent it however it did not do it correctly :S

1 Answer

Henrik Hansen
Henrik Hansen
23,176 Points

Because fetchAll() returns both the associated array (column names as key) as well as the numerical array. You can set the fetch mode as an argument: PDO fetchAll

Or you can use the regular fetch() witch returns one row at a time, and loop it to get all the rows from your query.