473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

$result = $stmnt->fetchAll(); returning duplicate keys for a singlequery



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
</===============>
Jan 11 '08 #1
2 4087
On Jan 11, 10:21 am, Rowan <yaard...@gmail.comwrote:
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
Jan 11 '08 #2
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.

Jan 13 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: john fabiani | last post by:
Hi, newbie question: PyPgSQL (postgres driver) returns a list (not a tuple O'Rielly states DBAPI returns a tuple) and most of the books describe how to work with tuples and dictionaries when...
9
by: NiQ | last post by:
Hello every one, this is about an array of string and may be have done several time before but i need it and wasnt able to find it so here is the problem i have an array of strings with contains...
0
by: Schlauberger | last post by:
I am currently developing a VB.Net App that utilized an MS Access file to store the data. My Report data source is a Parameter Query in MS Access when the report loads the parameter is prompted...
17
by: Roland Hall | last post by:
Is there a way to return multiple values from a function without using an array? Would a dictionary object work better? -- Roland Hall /* This information is distributed in the hope that it...
3
by: Sean Tynan | last post by:
I want to find out the best way for a method to notify calling code of situations such as validation errors, etc. that may occur during method execution. e.g. say I have a method (business...
5
by: kelmen | last post by:
Try the below simple program. It give expected result. 1 1 2 2 Then toggle the statements in private static int sinc(), to use Test._num ++ .
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
13
by: Karl Groves | last post by:
I'm missing something very obvious, but it is getting late and I've stared at it too long. TIA for responses I am writing a basic function (listed at the bottom of this post) that returns...
13
by: jfarthing | last post by:
Hi everyone! I am using the script below to search a db. If the is more than one match in the db, all goes well. But if there is only one match in the db, nothing gets displayed. Any...
8
by: jodleren | last post by:
Hi! I have a function, a part of my code which I can use as a function. It will return 2 arrays, and I am wondering what way to do so. Both arrays hold strings, there are no special keys. 1)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.