Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] Problem with perl CGI

Expand Messages
  • Chris Borokowski
    1) Does Apache have rights to read the file? 2) It might be worth including the file flush configuration, $| = 1; ...
    Message 1 of 2 , Jun 1, 2007
    • 0 Attachment
      1) Does Apache have rights to read the file?

      2) It might be worth including the file flush
      configuration, $| = 1;


      --- Ramesh Polepalli <ramesh.polepalli@...>
      wrote:

      > 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/html\n\n";
      >
      >
      >
      > # 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>Connected succesfully
      > <br>Query String : select
      > * from second_level order by aler_id
      > DESC<br>Succesfully fetched rows
      > from database<br>
      >
      >
      >
      >
      >
      > Output observer on Web
      >
      > ===================
      >
      >
      > before connecting
      > Connected succesfully
      > Query String : select * from second_level order by
      > aler_id DESC
      > Problem while fetchingthe rows from database
      >
      >
      >
      > Thanks in advance for the help.
      >
      >
      >
      === message truncated ===


      User Interface design blog
      http://user-advocacy.blogspot.com/
      Code::Design::UI::Consulting
      http://www.dionysius.com/


      ____________________________________________________________________________________
      Luggage? GPS? Comic books?
      Check out fitting gifts for grads at Yahoo! Search
      http://search.yahoo.com/search?fr=oni_on_mail&p=graduation+gifts&cs=bz
    Your message has been successfully submitted and would be delivered to recipients shortly.