#!/usr/bin/perl # # # # # # # # # # # # # # # # # # # Phil's mySQL/CGI front end # # Version 1.0 # # http://phillipmassyn.tripod.com # # # # # # # # # # # # # # # # # # # use DBI; print "Content-type: text/html\n\n"; $title = "Phil's mySQL/CGI frontend"; $version = "Version 1.0"; print "$title $version\n

$title

\n$version
"; %FORM = &unweb; $func = $FORM{func}; $footer = "
\n"; if($func eq "") { print <
Server
Port
Database
Username
Password
SQL
LOGIN ; } if($func eq "login") { $sql = $FORM{sql}; $user = $FORM{user}; $server = $FORM{server}; $password = $FORM{password}; $db = $FORM{db}; $port = $FORM{port}; print <SQL
SQL
ADDIT ; if($sql ne "") { $dbh = DBI->connect("DBI:mysqlPP:database=$db;host=$server;port=$port", $user, $password) or &error("DB Error: " . $DBI::errstr . ""); $sth = $dbh->prepare($sql) || &error("DB Error: \"" . $dbh->errstr . "\" while preparing SQL statement \"$sql\"",""); $sth->execute() || &error("DB Error: " . $dbh->errstr . " while preparing SQL statement \"$sql\"",""); print "

Output

\n"; print "\n"; while (@ary = $sth->fetchrow_array()) { print "\n"; foreach $field (@ary) { chomp($field); print " \n"; } print "\n"; } print "
$field
"; $sth->finish(); $dbh->disconnect(); } } print $footer; sub error { $txt = $_[0]; print "
\n"; print "\n"; print "\n"; print ""; print "

ERROR

ERROR: $txt
\n"; print "
\n"; print "$footer"; exit(0); } sub unweb { local $buffer; local @pairs; local $pair; local $name; local $value; if($ENV{QUERY_STRING} eq "") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else { #$buffer = $ENV{QUERY_STRING}; &error("Sorry -- the GET method is not supported. It is a security risk."); } @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/~!/ ~!/g; $MWSFORM{$name} = $value; } return %MWSFORM; }