Hi -

Tumurbaatar S. wrote:
I use pg_fetch_array() to get a record content. But it seems that
to access elements of  the returned associative array, I should
use lowercase field names. Is there any way to use case-insensitive
field names?

This is how Postgres works: it always returns arrays indexed with lowercase results. AFAIK there's no way to change this behavior from PHP.

In general, it's important to know that different databases do this differently:

- MySQL will return case matching the case of column names in the db -- or if you specify column names in your select clause (SELECT myColUmnName FROM ...) then the case of the array will match the case you use in your SELECT clause.
- Oracle will return all UPPERCASE column names.
- SQLite is configurable (defaults to mixed case)
- PostgreSQL returns all lowercase
... etc.

Of course, as someone mentioned, you can always col strtolower() when trying to access a column from postgres result set:

        $arr = pg_fetch_array($q);
        $value = $arr[ strtolower($mixedCaseColName) ];

It's best practice to use a database abstraction layer that provides column name case changing portability features -- like PEAR::DB or Creole. That way you can always use a single case (e.g. lowercase) for accessing columns and you won't have to rewrite all your code when you try to deploy your app on Oracle.


PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to