use strict;
use DBI;
use CGI qw(:all);
use CGI::Carp qw(fatalsToBrowser);
$|++;
print header ();
print start_html;
my $db_username="user";
my $db_password="password";
my $db_serverstring="DBI:Driver:here";
my $dbh = DBI->connect ($db_serverstring, $db_username, $db_password) || die ("Cannot connect to database -- DBI reports ", $DBI::errstr);
print "\n";
if (param("view")) {
h3"
Viewing tables";
my @tables = param("view");
foreach (@tables) {
my $sql = $dbh->prepare ("sp_columns $_") || die;;
my $sth = $sql->execute or die "no ".$DBI::errstr;
print h3("Viewing table $_"),"\n";
my $THdone;
while (my $result_ref = $sql->fetchrow_hashref()){
unless ($THdone) {
foreach (sort keys %$result_ref) {
print "| $_ | ";
}
$THdone = "yes, indeedy!";
}
print "";
foreach (sort keys %$result_ref) {
if (! defined $$result_ref{$_}) {print "| undef | ";next}
print "$$result_ref{$_} | ";
}
print "
\n";
}
print "
";
}
} else {
print h2"Viewing sp_help";
print start_form;
my $sql = $dbh->prepare ("sp_help") || die;;
my $sth = $sql->execute or die "no ".$DBI::errstr;
print "\n| Select me! | ";
my $THdone;
while (my $result_ref = $sql->fetchrow_hashref()){
unless ($THdone) {
foreach (sort keys %$result_ref) {
print "$_ | ";
}
$THdone = "yes, indeedy!";
}
print "| ",checkbox(-name=>"view",-checked=>"", -value=>"$$result_ref{Name}")," | ";
foreach (sort keys %$result_ref) {
if (! defined $$result_ref{$_}) {print "--undef-- | ";next}
print "$$result_ref{$_} | ";
}
print "
\n";
}
print "
";
print submit;
print end_form;
}
print end_html;