checking presence of table columns in mysql

Lynn David Newton plug-discuss@lists.plug.phoenix.az.us
Mon, 10 Feb 2003 21:42:38 -0700


  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