php: case-INsensitive variables?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cowboyx@automatictaxistop.com

    php: case-INsensitive variables?

    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)

  • Alvaro G. Vicario

    #2
    Re: php: case-INsensitive variables?

    *** cowboyx@automat ictaxistop.com escribió/wrote (17 Feb 2005 11:58:19
    -0800):[color=blue]
    > PostgreSQL (and MySQL, to the best of my knowledge) are
    > case-insensitive, so selecting columnName1 will return columnname1.[/color]

    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
    +- http://www.demogracia.com (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
    --

    Comment

    • Chung Leong

      #3
      Re: case-INsensitive variables?

      <cowboyx@automa tictaxistop.com > wrote in message
      news:1108670299 .228645.127090@ c13g2000cwb.goo glegroups.com.. .
      [color=blue]
      > (apparently PHP2 was case-insensitive, so I hope there's an INI tweak
      > that will restore this someplace)
      >[/color]

      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_ke y_case() before the extraction.


      Comment

      • noSpam

        #4
        Re: php: case-INsensitive variables?

        Alvaro G. Vicario wrote:[color=blue]
        > *** cowboyx@automat ictaxistop.com escribió/wrote (17 Feb 2005 11:58:19
        > -0800):
        >[color=green]
        >>PostgreSQL (and MySQL, to the best of my knowledge) are
        >>case-insensitive, so selecting columnName1 will return columnname1.[/color]
        >
        >
        > 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 ;-)
        >
        >[/color]
        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>

        Comment

        Working...