#!/usr/local/bin/perl use Date::Manip; use DBI; main(); sub main { my ($table,$field,$type,$n,$key,$def,$ex) = @$row; my $dbase="dbName"; my $user="userName"; my $pass="passWord"; my $db = DBI->connect ("dbi:mysql:$dbase", "$user","$pass"); my $firstLine="header - 1st line"; my $secondLine="header - 2nd line"; my $date = UnixDate("today","%B %e, %Y"); ############# format STDOUT_TOP = @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $firstLine @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $secondLine Last Modified: @<<<<<<<<<<<<<<<<<<<<<<< $date PAGE: @<<<<<< $% . format TABLEHEADER = ------------------------------------------------------------------------------- Field Type Null Key Default Extra ------------------------------------------------------------------------------- . format STDOUT = @<<<<<<<<<<< @<<<<<<<<<<<<< @<<<<<<< @<<<<<<<< @>>>>>> @|||||||||||||| $field, $type $n $key $def $ex ------------------------------------------------------------------------------- . format TABLE = @||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| $table . format NEWLINE = . format ENDTABLE = ------------------------------------------------------------------------------- . ##################### my $std = select (STDOUT); my $tableRefs = getData ($db, "show tables"); foreach my $tab (@$tableRefs) { $~=TABLE; $table = "TABLE: $$tab[0]"; write TABLE; $~=NEWLINE; write NEWLINE; $~=TABLEHEADER; write TABLEHEADER; $~=STDOUT; my $rowRefs = getData ($db, "describe $$tab[0]"); foreach my $row (@$rowRefs) { ($field,$type,$n,$key,$def,$ex) = @$row; write STDOUT; } $~=ENDTABLE; write ENDTABLE; $~=NEWLINE; write NEWLINE; } $db->disconnect(); } sub getData { my ($db,$sql)=@_; my $query=$db->prepare("$sql"); $query->execute(); my $rows = $query->fetchall_arrayref(); $rows; }