#!/usr/bin/perl -wT # Title : list_db.pl # Function : Quick and dirty method to view mysql database tables # Author : Pascal Schiks (C) 2006 GNU/GPL # This program may be freely distributed. # You may change te code if you wish, # However you may not remove the authors name (Pascal) # This PERL script requires the modules CGI and DBI use strict; use CGI qw(:standard); use DBI; # Configuration my $version="v1.5"; my $db_host="localhost"; my $db_user="root"; my $db_passwd=""; # Variables my $db=""; my $db_table; my $db_title="None Selected"; my $table_title="Not Selected"; my $mode=""; if(defined(param('mode'))) { $mode=param('mode'); } if(defined(param('db_name'))) { $db=param('db_name'); } if(defined(param('db_table'))) { $db_table=param('db_table'); $table_title=$db_table; } if(defined(param('db'))) { $db=param('db'); if($db ne "") { $db_title=$db; } } else { $mode="databases"; } print header; print "\n" . "\n" . "List db : $db_title : $table_title\n"; print "\n"; print ""; print "\n"; print "
list_dbList DB : $db_title " . "TABLE : $table_title $version
"; print "
\n" . "Databases\n" . "tables\n" . "
\n
\n"; { my $dsn = "DBI:mysql:$db:$db_host"; my $dbh = DBI->connect($dsn,$db_user,$db_passwd); if($dbh) { my $sth; my @data; if(defined($db_table)) { print "Back
\n"; print "\n"; $sth = $dbh->prepare("describe $db_table"); $sth->execute(); if($mode eq "describe") { print "\n"; while(@data=$sth->fetchrow()) { print ""; foreach(@data) { print ""; } print "\n"; } } else { print ""; while(@data=$sth->fetchrow()) { print ""; } print"\n"; $sth = $dbh->prepare("select * from $db_table"); $sth->execute(); while(@data=$sth->fetchrow()) { print ""; foreach(@data) { print "" } print "\n"; } } print "
NameType KeyDefaultOptions
$_
$data[0]
$_
\n"; } else { if($mode eq "databases") { $sth = $dbh->prepare("show databases"); $sth->execute(); print "\n" . "\n"; while(@data=$sth->fetchrow()) { print "" . "" . "\n"; } print "
Available databases
$data[0]
\n"; } else { $sth = $dbh->prepare("show tables"); $sth->execute(); print "\n" . "\n"; while(@data=$sth->fetchrow()) { print "" . "" . "" . "\n"; } print "
Available tables
$data[0]D
\n"; } } $dbh->disconnect(); } else { print "Error, connecting $dsn
\n"; } } print "\n" . "\n";