It's pretty much essential to use CGI.pm. (perldoc CGI)
You might want to check out a framework like CGI::Application
and Template Toolkit. May look like overkill for what
you're doing, but their examples will get you well started.
----- Original Message -----
From: "Ramesh Polepalli" < ramesh.polepalli%40mformation.com">ramesh.polepalli
mformation.com>
To: < perl-beginner%40yahoogroups.com">perl-beginner
yahoogroups.com>
Sent: Friday, June 01, 2007 3:14 AM
Subject: [PBML] Problem with perl CGI
> Hi,
>
> I am new to perl CGI and writing a small web based application.
>
>
>
> When I run the script from CLI, my Script is able to connect to
> database,
>
> where as when I use the same script on apache I am unable to connect to
>
> database.
>
>
>
>
>
> I also noticed one more case,
>
>
>
> I have stored database access details in a file which will be read by
> the
>
> script during execution.
>
>
>
> On printing the contents read from file, they are printed on command
> line but
>
> on web it is not.
>
>
>
> Can some one help me to understand if I am missing something.
>
>
>
>
>
> The script for your reference is as follows.
>
> =====================================
>
>
>
> #!/usr/bin/perl
>
> use DBI;
>
> my $x="";
>
> my $sql1="";
>
> my $exe;
>
> my %ConfigValue;
>
> my $returnstring="";
>
>
>
>
>
> # Read the configuration from file to determine database credentials.
>
> my $cfgfile="./dbconnect";
>
> open (CONFIG,$cfgfile);
>
>
>
> while (<CONFIG>) {
>
> chomp; # no newline
>
> s/#.*//; # no comments
>
> s/^s+//; # no leading white
>
> s/s+$//; # no trailing white
>
> next unless length; # anything left?
>
> my ($var, $value) = split(/s*=s*/, $_, 2);
>
> $value=~ s/r//g;
>
> $ConfigValue{$var} = $value;
>
> }
>
> print "Content-Type: text/htmlnn";
>
>
>
> # connect to database
>
> my
> $dns="DBI:mysql:database=$ConfigValue{'DBINSTANCE'};host=$ConfigValue{'D
> BSERVER'};port=$ConfigValue{'DBPORT'}";
>
> $db = DBI->connect($dns, $ConfigValue{'DBUSER'},
> $ConfigValue{'DBPASSWORD'});
>
>
>
> if($db->{'mysql_errno'})
>
> {
>
> print ("<br> Problem while connecting to database
> <br>$db->{'mysql_error'}");
>
> }
>
> else
>
> {
>
> print "Connected succesfully <br>";
>
> $sql1="select * from second_level order by aler_id DESC";
>
> print "Query String : $sql1<br>";
>
> $exe=$db->prepare($sql1);
>
> if(!$exe->execute())
>
> {
>
> print "Problem while fetchingthe rows from
> database<br>$exe->{'mysql_error'}";
>
> }
>
> else
>
> {
>
> print "Succesfully fetched rows from
> database<br>";
>
> #
row= $exe->fetchrow_array();
>
> }
>
> }
>
>
>
> Output observer on Command Line
>
> ==================
>
> -bash-3.00# perl displayalert.cgi
>
> Content-Type: text/html
>
>
>
> <br>before connecting<br>