This might not be the best way to do it, but here is a way to do it in PERL. If you are looking for a PHP script to do it online, that would be easier to make.
use DBI;
$driver = "mysql";$hostname="localhost";$database="db";$port=3306;$user="root";$password="";
$dsn = "DBI:$driver:database=$database;host=$hostname;port=$port";
$dbh = DBI->connect($dsn, $user, $password) || die ("connection failed");
my $data=$dbh->prepare("DESCRIBE table");
$data->execute;
undef @TYPE_ARRAY;
while (my $ref = $data->fetchrow_arrayref())
{($junk,$TYPE_ARRAY[$i++])= ($ref->[1] =~ /(()(\d{1,3})/);}
my $data=$dbh->prepare("SELECT * FROM table");
$data->execute;
while (my $ref = $data->fetchrow_arrayref())
{
for ($i=0;$i<@TYPE_ARRAY;$i++)
{$out .= sprintf("% $TYPE_ARRAY[$i]s",$ref->[$i]);}
$out .= "\n";
}
print $out;