checking presence of table columns in mysql

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Lynn David Newton
Date:  
Subject: checking presence of table columns in mysql
Mike> /_Does anyone know of a SQL based way to check for
Mike> /_the existence of a particular column by name?


Mike> Hmmm, have you tried looking in the array:


Mike> my $names = $sth->{NAME} ;


Your suggestion is a bit minimalist, but was sufficient
for me to discover that this works:

  $sth = $dbh->prepare("select * from tablename");
  $sth->execute;
  # my $names = $sth->{NAME};
  for ($i=1; $i <= $sth->{NUM_OF_FIELDS}; $i++) {
      print "Column $i is called $sth->{NAME}->[$i-1]\n";
  }


Shazam. Thanks a bunch.

--
Lynn David Newton
Phoenix, AZ