On Thu, 14 Jun 2001 15:16:05 -0700, traja wrote:
>How do I get the headers (column names) when I do a select thro' DBI.
>fetchrow will fetch only the data. I need to display the headers as
>well.
Simple. A statement handler has several attributes. See perldoc DBI for
a rather complete list. Amongst those:
NAME column names, default case
NAME_uc column names, upper case
NAME_lc column names, lower case
These all return an array ref, which, when dereferenced, gives you the
names of the columns from your select statement.
An example:
my $sth = $dbh->prepare("SELECT NAME, ID, AGE FROM PEOPLE
WHERE AGE<21");
$sth->execute;
local($\, $,) = ("\n", "\t");
print @{$sth->{NAME}};
while(my @data = $sth->fetchrow) {
print @data;
}
--
Bart.