in reply to List columns for a MySQL table

Personally, I'd do this instead:
my $sth = $dbh->prepare("SELECT * FROM $table WHERE 1=0"); $sth->execute; my @cols = @{$sth->{NAME_lc}}; $sth->finish;

Replies are listed 'Best First'.
Re^2: List columns for a MySQL table
by EvanK (Chaplain) on Jun 28, 2006 at 17:25 UTC
    that'd certainly work as well :)

    it'll throw an error as is, though, you need a semicolon to end the SQL statement

    apparently, my server is strangely configured or something, as this isnt the norm.

    __________
    Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
    - Terry Pratchett

      Sorry, you're wrong. AFAIK, no DBI driver requires a semicolon at the end of a SQL statement and many will throw an error if you put one in (though DBD::mysql seems to allow, but not require it).

      update : To quote from the DBI docs: "Some command-line SQL tools use statement terminators, like a semicolon, to indicate the end of a statement. Such terminators should not normally be used with the DBI."

        despite what the DBI docs say, every query i run through DBD::mysql fails unless its terminated with a semicolon. mabye theres something strange about the server i'm on, though :shrug:

        edit: could be that i'm using mysql 5.0, which has some...oddities with DBD::mysql

        __________
        Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
        - Terry Pratchett