Re: PostgreSQL lib and character case

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

Hans

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux