When I pass the URL, I want it to parse the args (works) go to the database and get the perlscript, execute the script and output back to the module to display the results. Sounds simple enough however, it simply is not working.. I have two examples in the database.package DashboardScripts::DashboardScripts; # File: DashboardScripts/DashboardScripts.pm use strict; use Apache2::RequestRec (); # for $r->content_type use Apache2::RequestIO (); # for $r->puts use Apache2::Const -compile => qw(OK DECLINED M_GET HTTP_METHOD_NOT_AL +LOWED); BEGIN { $| } use Data::Dumper; sub handler { my $r = shift; my $ref; my $post; #my $host = $r->get_remote_host; unless ($r->method_number == Apache2::Const::M_GET) { $r->allowed($r->allowed | (1<<Apache2::Const::M_GET)); return Apache2::Const::DECLINED; } $r->content_type('text/html'); map { $_ =~ s/\+/ /g; my ($key, $val) = split(/=/,$_,2); foreach ($key, $val) {$_ =~ s/%([A-Fa-f0-9]{2})/pack("c",h +ex($1))/ge}; $$ref{$key} .= (defined($ref->{$key})) ? "\0$val" : $val; } split/[&;]/,$r->args(); #mysql> desc defaultscripts; #+----------+-------------+------+-----+---------+-------+ #| Field | Type | Null | Key | Default | Extra | #+----------+-------------+------+-----+---------+-------+ #| name | varchar(25) | NO | PRI | | | #| script | text | YES | | NULL | | #+----------+-------------+------+-----+---------+-------+ #2 rows in set (0.01 sec) exit Apache2::Const::DECLINED if ($ref->{name} eq ""); my @Raw_DB_Data; my $dbh = DBI->connect("DBI:mysql:dashboards", 'id', 'passwd', { PrintError => 0, # warn( ) on errors RaiseError => 0, # don't die on error AutoCommit => 1, # commit executes immedi +ately } ); my $sql = "SELECT script FROM scripts where name='$ref->{name}'" +; my $script; my $sth = $dbh->prepare("$sql"); if ($sth->execute) { while(my $row_hash = $sth->fetchrow_hashref) { $script = "$row_hash->{script}"; + } $post .= "$script"; $post .= eval "$script; 1" or warn $@; $sth->finish(); } ################################################ $r->puts(<<"END"); $post END undef $post; undef $r; undef $sth; undef $dbh; return Apache2::Const::OK; } END { } 1;
and#!c:/perl/bin/perl.exe use strict; for(my $x=0; $x<=100000;$x++){ print "$x<br>"; }
The above prints the script that it got back from the db just fine. But only returns the 1 after. Ideas on what I might be doing wrong here. Thanksfor(my $x=0; $x<=100000;$x++){ print "$x<br>"; }
In reply to Re^2: Executing code stored in a database..
by jbinaustin
in thread Executing code stored in a database..
by jbinaustin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |