#!/fellow/monks.pl
Here's a quick dirty little CGI script I wipped up that I use to administer my mySQL server. Of course, you will have to know your SQL statements on this one (I mean, it's a quick and dirty ;-)
You need DBI and mysqlPP installed.
#!/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 "<html><head><title>$title $version</title></head>\n<h1>$title</ +h1>\n<i>$version</i><hr>"; %FORM = &unweb; $func = $FORM{func}; $footer = "<hr></html>\n"; if($func eq "") { print <<LOGIN; <form method=post> <table border=1> <tr> <th>Server</th> <td><input type="text" name="server"></td> </tr> <tr> <th>Port</th> <td><input type="text" name="port" value="3306"></td> </tr> <tr> <th>Database</th> <td><input type="text" name="db"></td> </tr> <tr> <th>Username</th> <td><input type="text" name="user"></td> </tr> <tr> <th>Password</th> <td><input type="password" name="password"></td> </tr> <tr> <th>SQL</th> <td><textarea cols="30" rows="10" name="sql"></textarea></td> </tr> <tr> <th></th> <td><input type="Submit" value="Login"></td> </tr> <input type="hidden" value="login" name="func"> </table> </form> LOGIN ; } if($func eq "login") { $sql = $FORM{sql}; $user = $FORM{user}; $server = $FORM{server}; $password = $FORM{password}; $db = $FORM{db}; $port = $FORM{port}; print <<ADDIT <h3>SQL</h3> <form method=post> <table border=1> <input type="hidden" name="server" value="$server"> <input type="hidden" name="port" value="$port"> <input type="hidden" name="db" value="$db"> <input type="hidden" name="user" value="$user"> <input type="hidden" name="password" value="$password"> <tr> <th>SQL</th> <td><textarea cols="30" rows="10" name="sql">$sql</textarea></ +td> </tr> <tr> <th></th> <td><input type="Submit" value="Execute"></td> </tr> <input type="hidden" value="login" name="func"> </table> </form> ADDIT ; if($sql ne "") { $dbh = DBI->connect("DBI:mysqlPP:database=$db;host=$server;por +t=$port", $user, $password) or &error("DB Error: <b>" . $DBI::errstr +. "</b>"); $sth = $dbh->prepare($sql) || &error("DB Error: \"" . $dbh->er +rstr . "\" while preparing SQL statement \"$sql\"",""); $sth->execute() || &error("DB Error: <b>" . $dbh->errstr . "< +/b> while preparing SQL statement \"<b>$sql</b>\"",""); print "<h3>Output</h3>\n"; print "<table border=1>\n"; while (@ary = $sth->fetchrow_array()) { print "<tr>\n"; foreach $field (@ary) { chomp($field); print " <td>$field</td>\n"; } print "</tr>\n"; } print "</table>"; $sth->finish(); $dbh->disconnect(); } } print $footer; sub error { $txt = $_[0]; print "<center>\n"; print "<table border=1>\n"; print "<tr><td><center><font color=\"#FF0000\"><h3>ERROR</h3></fon +t></center></td></tr>\n"; print "<tr><td>ERROR: $txt</td></tr>"; print "</table>\n"; print "</center>\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 sec +urity 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; }
Thanks!
#!/massyn.pl The early worm gets caught by the bird.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI frontend for mySQL
by PodMaster (Abbot) on Feb 28, 2003 at 11:29 UTC | |
|
Re: CGI frontend for mySQL
by Ryszard (Priest) on Feb 28, 2003 at 14:02 UTC | |
|
Re: (nrd) CGI frontend for mySQL
by newrisedesigns (Curate) on Feb 28, 2003 at 16:56 UTC | |
by jonadab (Parson) on Feb 28, 2003 at 18:29 UTC | |
|
Re: CGI frontend for mySQL
by Anonymous Monk on Mar 01, 2003 at 00:01 UTC |