use CGI;
use DBI;
my $q = new CGI;
my $user = ''; # Be sure to add your username and password here
my $pass = '';
my $db = $q->param('db');
my $table = $q->param('table');
my $fields = $q->param('fields') || '*';
my $where = $q->param('where');
my $order = $q->param('order');
my $dbh = DBI->connect("DBI:mysql:$db","$user","$pass");
my @valid = qw( ); # ip's that are allowed in here
my $from = $ENV{'REMOTE_ADDR'};
my $x = 0;
if (($db)&&($table)) {
foreach my $i (@valid) {
if ($from =~ /$i/i) {
my $sth = $dbh->prepare(qq! SELECT $fields FROM $table $where $order !);
$sth->execute();
my @fld = @{ $sth->{NAME} };
my $ar = $sth->fetchall_arrayref();
$sth->finish();
my $rows = (!$ar ? 0 : scalar @{$ar});
print "Content-type: \r\n\r\n";
my $flds = join '","', @fld;
print "\"$flds\"\r\n";
if ($rows > 0) {
for my $i (0 ..$rows - 1) {
my $vals = join '","', @{ $ar->$i };
print "\"$vals\"\r\n";
}
}
$x++;
}
}
}
if ($x == 0) {
# invalid user
my $q = new CGI;
print $q->header(), $q->start_html(-title=>'Illegal User');
print "<div align=center><h2>Invalid Page</h2>";
print "<br><br>";
print "The page accessed is not a valid page.<br>";
print "<br><a href=\"/index.htm\">Return Home</a>";
print "<br></div>";
print $q->end_html;
}
$dbh->disconnect();
exit;
link to it like this:
http://server/cgi-bin/db.csv?db=dbname&table=tablename
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Database Downloads
by SuperCruncher (Pilgrim) on Jul 22, 2000 at 14:17 UTC | |
by steveAZ98 (Monk) on Jul 23, 2000 at 03:23 UTC | |
|
RE: Database Downloads
by lachoy (Parson) on Aug 11, 2000 at 01:40 UTC |