[pm-h] Fwd: Fields names froma table

Bart Hampshire bart_hampshire at yahoo.com
Thu Mar 11 12:01:49 PST 2010


You might also try (you might have to change the query to actually return a row):


my $sth = $dbh->prepare("select * from myTable where 1=2");
$sth->execute;
my $rc = $sth->fetchrow_hashref;
foreach my $key (keys %{$rc}) {
  print $key;
}
$sth->finish;
Sorry for any typos as I'm not using a proper keyboard.

Bart

Begin forwarded message:

From: Michael Dickens <cmdickens at gmail.com>
Date: March 11, 2010 13:43:17 CST
To: "Houston.pm located in Houston, TX." <houston at pm.org>
Subject: Re: [pm-h] Fields names froma table
Reply-To: "Houston.pm located in Houston, TX." <houston at pm.org>


Hi Fraser,
have you tried using a query 'DESC my_table' and then fetchrow_array something like:

my $sth = $dbh->prepare("DESC my_table");
$sth->execute();
my @fields = $sth->fetchrow_array;
$sth->finish();



Michael

On Thu, Mar 11, 2010 at 11:32 AM, Fraser Baker <flbaker at sbcglobal.net> wrote:
Hi:
 
OK, I finally have a question.
 
How do I get a list of field names from a mySQL table using DBI? I don't need the values.
 
I have put my time in, but can't get it to work.
 
Fraser

_______________________________________________
Houston mailing list
Houston at pm.org
http://mail.pm.org/mailman/listinfo/houston
Website: http://houston.pm.org/



-- 
easy as Perl
_______________________________________________
Houston mailing list
Houston at pm.org
http://mail.pm.org/mailman/listinfo/houston
Website: http://houston.pm.org/



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/mailman/private/houston/attachments/20100311/94ccb1ea/attachment.html>


More information about the Houston mailing list