Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Getting a list of columns from a MySQL Table

by mp (Deacon)
on Jul 22, 2002 at 22:27 UTC ( [id://184261]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://184261]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-19 09:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found