$result = $stmnt->fetchAll(); returning duplicate keys for a single
am 11.01.2008 19:21:18 von Rowan
For some reason when I do a fetchall on a PDO query the array returned
has duplicated keys. see below.
SELECT name_first, name_last, personal_street, personal_phone_home,
personal_phone_cell FROM contacts WHERE id = 8;
$result = $stmnt->fetchAll();
<====krumo array dump===>
0 (Array, 12 elements)
*
id (Integer) 8
*
0 (Integer) 8
*
name_first (String, 8 characters ) Martinez
*
1 (String, 8 characters ) Martinez
*
name_last (String, 10 characters ) Conc*****
*
2 (String, 10 characters ) Con******
*
personal_street (String, 20 characters ) *****W. Buckthorn
*
3 (String, 20 characters ) ****W. Buckthorn
===============>
Re: $result = $stmnt->fetchAll(); returning duplicate keys for a
am 11.01.2008 19:57:02 von Rowan
On Jan 11, 10:21 am, Rowan wrote:
> For some reason when I do a fetchall on a PDO query the array returned
> has duplicated keys. see below.
>
> SELECT name_first, name_last, personal_street, personal_phone_home,
> personal_phone_cell FROM contacts WHERE id = 8;
> $result = $stmnt->fetchAll();
>
Helps when you read. For anyone curious the answer is below.
Controls how the next row will be returned to the caller. This value
must be one of the PDO::FETCH_* constants, defaulting to
PDO::FETCH_BOTH.
*
PDO::FETCH_ASSOC: returns an array indexed by column name as
returned in your result set
*
PDO::FETCH_BOTH (default): returns an array indexed by both
column name and 0-indexed column number as returned in your result set
Re: $result = $stmnt->fetchAll(); returning duplicate keys for a single query
am 13.01.2008 20:13:05 von Peter Pei
To fetch assc is the best, so that your code depends less on the physical
structure of the table. both wastes space, and index not only has too much
dependency, but also makes code less readable. when $row['name_last'] has
clear meaning, $row[1] does not.