Their is a variety of ways to achieve what you want. Remember anything you can do in SQL in the MySQL monitor can be done through the DBI. Do you use SHOW COLUMNS in the monitor? Well, why not use it in your programme?
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
.}
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.
Go and try this sort of stuff out, and come back with more specific questions wehn you get stumped.
jdtoronto
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.