PDO question: any way to resolve duplicate column names with PDO_FETCH_ASSOC?
| From: | Matthew Peters | Date: | Mon, 16 May 2005 13:53:55 +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-2372@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, 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.
TIA
--
Matthew Peters
IBM Hursley Park