php: case-INsensitive variables?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Is there a way to configure PHP to use case-insensitive variable names?
I'd like to do this...

$dbVars = pg_query( $connection, "SELECT columnName1, columnName2,
columnName3 FROM table WHERE id=1" );
$dbVars = pg_fetch_array( $dbVars );
extract( $dbVars[0] );
echo( $columnName1 );

PostgreSQL (and MySQL, to the best of my knowledge) are
case-insensitive, so selecting columnName1 will return columnname1. In
my last project, a 60-table, year-long event, this was just a constant,
numbing (yet minor) source of frustration, and I'd like to avoid it
this next time.

My other option is to use PostgreSQL in a case-sensitive mode, but
there's no switch to just "turn on"; it requires another level of
annoying syntax within the queries, and tweaking PHP seems like a much
better solution.

(apparently PHP2 was case-insensitive, so I hope there's an INI tweak
that will restore this someplace)

Re: case-INsensitive variables?

Quoted text here. Click to load it

As far as I know it cannot be done without tweaking the source code. It'd
easier to stick with lowercase-only variable names, then pass the array
through array_change_key_case() before the extraction.

Re: php: case-INsensitive variables?

*** escribió/wrote (17 Feb 2005 11:58:19
Quoted text here. Click to load it

I can't speak for Postgre but MySQL returns column names using the exact
case you specified.

In any case, I think typing variable names always the same is a good
programming practice that makes code cleaner. Among other things, it
prevents problems like the one you're facing ;-)

-+ Álvaro G. Vicario - Burgos, Spain
+- (la web de humor barnizada para la intemperie)
++ Manda tus dudas al grupo, no a mi buzón
-+ Send your questions to the group, not to my mailbox

Re: php: case-INsensitive variables?

Alvaro G. Vicario wrote:
Quoted text here. Click to load it
MySQL column names are definately case sensitive. You need to pick a
variable/column naming approach that helps to prevent weird and
wonderful problems. I use totally lower case, but others may prefer
diffent methods. Just be consistent - avoids vast amounts of grief <g>

Site Timeline