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

Andrew McMillan <[email protected]> Tue, 20 Nov 2012 08:52:23 +1300
Newsgroups gmane.comp.db.postgresql.php
Organization Morphoss Ltd
Message-ID <[email protected]>
--=-+rbmZf3V7kvsXm/CMIn8
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Mon, 2012-11-19 at 10:45 -0600, David McMath wrote:
> Dear List,
>=20
> I'm converting a PHP project from using Oracle to using Postgres.=20
> Apparently, pg_fetch_object() wants to create an object with field names=
=20
> lowercase by default.  In the Oracle analogue, they're uppercase.  So=20
> all my code's "$obj->FIELD" references need to change to "$obj->field".
>=20
> Is there any way to tell PHP or Postgres to change the default=20
> 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,=20
> we're using "DB" (not MDB2) for the database connections, and I don't=20
> 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.
--=20
------------------------------------------------------------------------
andrew (AT) morphoss (DOT) com                            +64(272)DEBIAN
              Does the turtle move for you?  www.kame.net
------------------------------------------------------------------------


--=-+rbmZf3V7kvsXm/CMIn8
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: This is a digitally signed message part
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iQIcBAABCAAGBQJQqo33AAoJEOr8/r+P646/baoP/3kfD67QlwDiEoLZV11tvhug
yq6TYE2L0daFIHZFgPI5pEa64KeMCZGXCc79QAylEZul+OwNAnHmYTfUn3iqOdal
ZdaotbHBPbMQfOYp6DOB6yKrmlge2V5ly68Vq+ha50LGx3bFV904dnYdvypaYckX
p5I9s2e/U/lKCKAu/V7krEtDHyQzXb4ttfu/lHmewy7LN6AiFRwI1/CmVFXP/F2x
urt5iGZLw2boKKK2/McJbcjzp4jgNVJdK8F/nNCz4GdukENU69ctHkyNVY7koYhn
uOKfWg8Vka3FKyFLp8/jXg4LjgogLfSE47puboLDqne9rAcw9I0YayjZ/+iSynds
/vmAHdN7CYDRzDs3fRQWAWASBwYNy7oaJRgFiOayu8XrkynBq+c9uDm9BqmWjK6p
Mrd7I2JK0JPdhholw89OLv049NkeFgOG0ntPFfEnC0LIw+waKYBomYgXH9+Objia
sJTsLDySvyKeYxviN/JKK4UhdhXQjCc/ZoHYh6vRO3BYh+kcYurPOLBeCP45PGb0
TNRFKlEUL6GCgjGcE8iKG0oqV3/EE9PlmGerrdFWJNieQ0hcRS6PArsQKjpqhhzC
MUtvr3BfrRAAwBBPLyd6B8KHh2k9QCZUDIkwKDPs7//3L6g8N6FTFN1Jt/LHNOpI
D3cTe17YNM0JxcV/zF8H
=a3Dg
-----END PGP SIGNATURE-----

--=-+rbmZf3V7kvsXm/CMIn8--