in reply to perl-mysql help - print table structure
Gives you the information about the table. You can take that info and then use it to build entire new tables! In my case I import a text file into a table where every field is of type VARCHAR and named 'fieldn'. Using this data form MySQL I map the input table fields to fields in the database, ALTER the table, add some fields and then append it to the destination table - all done using MySQL SQL statements via the DBI.sub getTableStructure { # need: $dbh # tablename # returns: hash of field(column) records my ($dbh, $tablename) = @_; my %struct_hash; my $SQL = "SHOW COLUMNS FROM $tablename"; my $sth = $dbh->prepare( $SQL ); $sth->execute(); while ( my $inphash = $sth->fetchrow_hashref() ) { . .whatever you need to do .}
Go and try this sort of stuff out, and come back with more specific questions wehn you get stumped.
|
|---|