PDO question: any way to resolve duplicate column names with PDO_FETCH_ASSOC?
| From: | Matthew Peters | Date: | Thu, 19 May 2005 13:54:11 +0000 |
| Subject: | PDO question: any way to resolve duplicate column names with PDO_FETCH_ASSOC? | ||
| Groups: | php.pecl.dev | ||
| Request: | Send a blank email to pecl-dev+get-2371@lists.php.net to get a copy of this message | ||
I really like the PDO_FETCH_ASSOC behaviour where I get back an associative
array indexed by column name, but I have a problem when there are two
columns with the same name in the result set: for example when I join two
tables that both contain a column called 'id', or 'name', for example.
Experiment shows that one of them hides the other.
I would really like it there a way to get both back and to know which was
from which table. The simplest solution to my mind would be if there were a
way to get the keys in the associative array to be qualified with table
name: 'table1.id' and
'table2.id', for example. Does anyone know of a way of doing this or
something similar?
You might think I should just use the PDO_FETCH_BOTH or PDO_FETCH_NUM and
step through the results, but I am writing some tooling where I do not
construct the SQL query in the first place but do need to inspect the result
set and know which column is which. My only choices at the moment seem to be
to either parse the SQL query or to get the user to tell me which columns
are which in the result set.
(This is attempt 2 to post this - first attempt bounced as I was not in
pecl-dev@pair1.php.net's list - excuse me if this appears twice)
--
Matthew Peters
IBM Hursley Park