Re: How to specify capitalization for column names in pg_fetch_object?

Поиск
Список
Период
Сортировка
От Andrew McMillan
Тема Re: How to specify capitalization for column names in pg_fetch_object?
Дата
Msg-id 1353354743.5803.7.camel@dave.home.mcmillan.net.nz
обсуждение исходный текст
Ответ на How to specify capitalization for column names in pg_fetch_object?  (David McMath <mcdave@stanford.edu>)
Список pgsql-php
On Mon, 2012-11-19 at 10:45 -0600, David McMath wrote:
> Dear List,
>
> I'm converting a PHP project from using Oracle to using Postgres.
> Apparently, pg_fetch_object() wants to create an object with field names
> lowercase by default.  In the Oracle analogue, they're uppercase.  So
> all my code's "$obj->FIELD" references need to change to "$obj->field".
>
> Is there any way to tell PHP or Postgres to change the default
> capitalization?

This has nothing to do with PHP, really, though obviously there can be
workarounds for this in connection libraries.  In PostgreSQL column
names are translated to lower case unless they are not enclosed in
double-quotes like "column_name".  In Oracle column names are translated
to upper case unless they are quoted.

So one answer would be to explicitly specify the case of the column and
to always refer to it in your SQL in double-quotes.


> In Perl, I'd use DBI and set FetchHashKeyName to "NAME_uc".  In PHP,
> we're using "DB" (not MDB2) for the database connections, and I don't
> see a similar-looking lever to pull on

You should probably use PDO, which has always seemed to be the closest
PHP comes to DBI, and look at using the "PDO_CASE_UPPER" flag on
connecting to the database.  This may do what you want.

Cheers,
                    Andrew.
--
------------------------------------------------------------------------
andrew (AT) morphoss (DOT) com                            +64(272)DEBIAN
              Does the turtle move for you?  www.kame.net
------------------------------------------------------------------------


Вложения

В списке pgsql-php по дате отправления:

Предыдущее
От: David McMath
Дата:
Сообщение: How to specify capitalization for column names in pg_fetch_object?
Следующее
От: David McMath
Дата:
Сообщение: Re: How to specify capitalization for column names in pg_fetch_object?