Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

return column names using DBI?

Status
Not open for further replies.

TheNewbie81

Technical User
Feb 12, 2007
15
IE
hi,

can anyone tell me whats the best way to return the column names for each table to a perl script. I have written a script that retrieves all the values in a table and formats it into HTML. The only thing is that I am unsure how to retrieve the column names. The perl module installed does not have the function column_info. Any ideas?
 
This came from some code I had just laying around
$sth=$dbh->prepare($query);
$sth->execute;
$num = $sth->{NUM_OF_FIELDS};
for $field (0..$num)
{
$column = $sth->{NAME}->[$field];
print "$column\n";
}


Normally I don't have a need to know what the column names are because when you do your query you usually ask for them in the order you want in the query.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top