#!/usr/bin/perl -wT BEGIN { $|=1; print "Content-type: text/html\n\n"; use CGI::Carp('fatalsToBrowser'); } use DBI; use CGI; $query = new CGI; $month = $query->param('m'); $year = $query->param('y'); $table_name = $month."_".$year; printf "Connecting to the database ............<br>\n"; ($dbhost, $dbname) = qw/xx.xxxxxxx.com.xx xxxxxxxxx/; ($user, $pass) = qw/xxxxxxxx xxxxxx /; $dbh = DBI->connect("DBI:mysql:hostname=$dbhost:database=$dbname", $us +er, $pass); printf "Creating temp table if not exist ............<br>\n"; $sql = "CREATE TABLE IF NOT EXISTS tmp_table (ClientIP Char(20),Qty IN +T)"; if (!$dbh->do($sql)) { printf "Error creating tmp_table table: " . $DBI::errstr; $dbh->disconnect; exit; } printf "Select from $table_name ............<br>\n"; $sql = "SELECT ClientIP, count(ClientIP) as Qty FROM " . $table_na +me; $sql .= " GROUP BY ClientIP"; $res = $dbh->prepare($sql); if ($res->execute) { while($data = $res->fetchrow_hashref) { $hits = int($data->{Qty}); if ($hits > 100) { printf "Insert " . $data->{ClientIP} . " - " . $data->{Qty} . " ...... +......<br>\n"; $sql = "INSERT INTO tmp_table (ClientIP,Qty) values (" +; $sql .= "'" . $data->{ClientIP} . "',"; $sql .= "'" . $data->{Qty} . "')"; if (!$dbh->do($sql) ) { printf "Error adding tmp_table table: $DBI::errstr +"; } } } } else { printf "Error selecting from " . $table_name ." table: $DBI:: +errstr\n"; } $res->finish; printf "that's all for now Folks!!<br>\n";
Edit by tye: title, READMORE
In reply to flushing CGI output by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |