in reply to Getting a list of columns from a MySQL Table

Try using "DESCRIBE table" instead of "LISTFIELDS table". This will give you column name, type, allownull, key, default, and extra. For more information on what you get, you may want to try the following inside your for loop:
use Data::Dumper; my $sth = $dbh->prepare("DESCRIBE $i"); $sth->execute; while(my $info = $sth->fetchrow_hashref) { print Dumper($info); }

Replies are listed 'Best First'.
Re: Re: Getting a list of columns from a MySQL Table
by c (Hermit) on Jul 22, 2002 at 22:37 UTC
    Thanks, I saw the fetchrow_hashref routine and tried something like:

    for my $i(sort @tables) { print uc $i . "\n\n"; ## get a list of columns for the table my $sth = $dbh->prepare("LISTFIELDS $i"); $sth->execute; my $row = $sth->fetchrow_hashref(); for my $header(keys %{$row}) { print " $header\n"; } $sth->finish; sleep 1; }

    but still no dice. I'll try your code and see what it yields. Thanks! -c

    A reply falls below the community's threshold of quality. You may see it by logging in.