checking presence of table columns in mysql

Página superior
Adjuntos:
Obtener este mensaje como un correo
+ (text/plain)
Eliminar este mensaje
Responder a este mensaje
Autor: Lynn David Newton
Fecha:  
Asunto: 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