I'm trying to write a code to retreive data from a database to an excel file, I achieved my code and everything is going good by running it through unix, but when I create a webpage to help users to extract data via internet I got an internal server error! anyone can help me???
thank you..
Expand|Select|Wrap|Line Numbers
- #!/usr/bin/perl
- use strict;
- use warnings;
- use DBI;
- use DBD::mysql;
- use lib qw(.);
- use Time::Local;
- use Spreadsheet::WriteExcel;
- my $query_string = $ENV{'QUERY_STRING'};
- my $query_string = "b.bug_id=on&b.assigned_to=on&pf.login_name=on&b.creation_ts=on&b.short_desc=on&pd.name=on&b.rep_platform=on";
- # Split the name-value pairs
- my @pairs = split('&', $query_string);
- my $dbh = DBI->connect('DBI:mysql:database=bugs;host=localhost', 'jinny', 'jinny',{RaiseError => 1, PrintError => 0}) or die $DBI::errstr;
- #create a new instance
- my $now = localtime time;
- my $workbook = Spreadsheet::WriteExcel->new("Report.xls");
- my $worksheet= $workbook->add_worksheet('report');
- $worksheet->write(0, 0, "Report generated on :$now");
- my $stmt = "SELECT ";
- my $counter = 0;
- foreach my $pair (@pairs)
- {
- (my $name, my $value) = split('=', $pair);
- $stmt = $stmt."$name, ";
- $worksheet->write(1, $counter, "$name" );
- $counter ++;
- }
- chop ($stmt);
- chop ($stmt);
- $stmt = $stmt." FROM bugs b, profiles pf, products pd WHERE b.assigned_to= pf.userid AND b.product_id = pd.id ORDER BY bug_id";
- my $sth = $dbh->prepare($stmt);
- $sth->execute();
- my $row=0;
- my $col=0;
- if($sth->rows){
- ++$row;
- while ( my $array_ref = $sth ->fetchrow_arrayref){
- $worksheet->write_row(++$row,$col,$array_ref);
- }
- print "Content-Type: text/html\n\n";
- print "<html><head>";
- print "<title>Report</title>";
- print "<body>";
- print "Data retrieved";
- print "</body>";
- print "</html>";
- }
- else {
- print "Content-Type: text/html\n\n";
- print "<html><head>";
- print "<title>Report</title>";
- print "<body>";
- print "No data retrieved \n";
- print "</body>";
- print "</html>";
- }
- $sth->finish();
- $dbh->disconnect();