List:General Discussion« Previous MessageNext Message »
From:Jay Flaherty Date:May 11 1999 4:10pm
Subject:Re:MySQL Perl DBD can not get fields' type
View as plain text  
The info returned is not very useful. Try this instead
$sth->prepare("SHOW FIELDS from $table");
$sth->execute;
my %type;
while(@row = $sth->fetchrow_array) {
	$type{$row[0]} = $row[1];
}
$sth->finish;
foreach $key(%type) {
	print "Field Name: $key Type: $type{$key}\n";
}
This gives you a hash of fieldname:type pairs keyed on field name.
(though some field types will include the length, i.e. char(20) but a 
good regular expression will take care of that ;-)

> Qiang Tan writes:

>  > > Could somebody tell me how to get the fields' type through DBI:DBD of
> Perl?
>  > > I tried one, but it does not work as stated in doc:

> Just fix:
> 
> $types = $sth->{types};
> 
> to
> 
> $types = $sth->{type};

Take care of your shoes...

Jay
fty@stripped
Thread
Re:MySQL Perl DBD can not get fields' typeQiang Tan4 May
  • Re:MySQL Perl DBD can not get fields' typeJani Tolonen11 May
    • Re:MySQL Perl DBD can not get fields' typeJay Flaherty11 May