AW: MySQL column_info() output order
"Selke, Gisbert W." <[email protected]> Thu, 7 May 2009 17:08:13 +0200
| Newsgroups | gmane.comp.db.mysql.perl |
|---|---|
| Message-ID | <DA5D2621C9566F488C32ACE506A7BB8968EAB4@wido-exch01.wido.bv.aok.de> |
Hallo Sebastian -- > -----Urspr=FCngliche Nachricht----- > Von: Sebastian Reinhardt [mailto:[email protected]]=20 > Gesendet: Donnerstag, 7. Mai 2009 15:26 > To query an MYSQL- database, I have written a short CGI/Perl-=20 > Script. It is working well, except the naming of the result=20 > table! I try to fetch the column names from my database, to=20 > use it for the result table's head. I get the names, no=20 > problem so far, but these names are not in same order, as=20 > stored in the database! >=20 > To fetch the names I use following code: >=20 > --------------snip------------------ > my $sth =3D $dbh->column_info(undef,$d_base,$d_table,'%'); > my $col_info =3D $sth->fetchall_arrayref(); > $sth->finish(); > my $i =3D 0; > foreach my $info(@$col_info) > { > $kat_info[$i]=3D@$info[3]; > $i++; > } > --------------snip------------------ Es ist einfacher ohne column_info() und funktioniert dann nicht nur = f=FCr Tabellen, sondern f=FCr beliebige SELECts: ---------------------- my $sth =3D $dbh->prepare(qq(select * from some_table were foo=3D'bla')) = or die "Yukk"; $sth->execute(); @kat_info =3D @{ $sth->{NAME_lc} }; # ... mach was mit @kat_info... while (my $aryref =3D $sth->fetchrow_arrayref()) { ... } ---------------------- \Gisbert -- MySQL Perl Mailing List For list archives: http://lists.mysql.com/perl To unsubscribe: http://lists.mysql.com/[email protected]