How to make PDO return fully qualified column names?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
iansmith
Forum Newbie
Posts: 3
Joined: Wed Sep 24, 2008 2:07 pm

How to make PDO return fully qualified column names?

Post by iansmith »

I have queries that return multiple tables joined together, and in many of the tables they have identical column names.

I can rename them manually with AS, but I would love to have PDO return an array with table dot column names instead of just column names.

Is there an option, or a patch that will do this? Thanks!
visu
Forum Newbie
Posts: 4
Joined: Fri Jun 06, 2008 2:48 pm

Re: How to make PDO return fully qualified column names?

Post by visu »

http://uk.php.net/manual/en/pdo.constants.php

PDO::ATTR_FETCH_TABLE_NAMES and PDO::ATTR_FETCH_CATALOG_NAMES look promising.
iansmith
Forum Newbie
Posts: 3
Joined: Wed Sep 24, 2008 2:07 pm

Re: How to make PDO return fully qualified column names?

Post by iansmith »

I stumbled onto those after I posted, but sadly they do not seem to be supported by any drivers, at least in php5-5.2.4 which I have.

I got the source and they are not used. I am going to try and patch the pdo_pgsql driver to use it and I will let you know how it goes.
iansmith
Forum Newbie
Posts: 3
Joined: Wed Sep 24, 2008 2:07 pm

Re: How to make PDO return fully qualified column names?

Post by iansmith »

Yuck yuck yuck.

I worked on patching the postgresql driver for php5 to return table names when the option was enabled, but sadly for me the c interface to postgresql has no clean way of getting the table name for a query result.

The dirty details are that for each column of a table being returned you can get the column name, but only an 'oid' of the table. Turning that into the name of the table requires executing database query which is a lot of overhead. I could cache each query as I go through each column, but that is too much work for now.

So my code just returns 'table_uid dot column_name' which is not terribly useful, but does show which columns belong together. :-)
Post Reply