List Info

Thread: Problem with perl CGI




Problem with perl CGI
country flaguser name
United States
2007-06-01 02:14:04

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/^s3;//; # 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=&quot;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-&gt;{'mysql_error'}&quot;;

}

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&lt;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.

Ramesh Polepalli

mFormation Technologies Inc.
Direct Line: +91 80 6620 5939
Switchboard: +91 80 6620 5900

http://www.mformation.com


Visit WWW.MFORMATION.COM and see how the MFORMATION SERVICE MANAGER can help you to transform your business.

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
Re: Problem with perl CGI
country flaguser name
United States
2007-06-01 09:55:32

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&quot; < ramesh.polepalli%40mformation.com">ramesh.polepallimformation.com>
To: < perl-beginner%40yahoogroups.com">perl-beginneryahoogroups.com>;
Sent: Friday, June 01, 2007 3:14 AM
Subject: [PBML] Problem with perl CGI

&gt; 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,
>
&gt; where as when I use the same script on apache I am unable to connect to
>
> database.
>
&gt;
>
>
>;
> I also noticed one more case,
&gt;
>
>
>; I have stored database access details in a file which will be read by
> the
>
> script during execution.
>
&gt;
>
> 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.
>
&gt;
>
>
&gt;
> The script for your reference is as follows.
>
>; =====================================
>
>
>
&gt; #!/usr/bin/perl
>;
> use DBI;
>;
> my $x="&quot;;
&gt;
> my $sql1=&quot;";
>
>; my $exe;
&gt;
> my %ConfigValue;
>
> my $returnstring="";
&gt;
>
>
&gt;
>
> # Read the configuration from file to determine database credentials.
>
> my $cfgfile=&quot;./dbconnect";;
>
> open (CONFIG,$cfgfile);
>
>;
>
> while (<CONFIG>) {
>
> chomp; # no newline
>
> s/#.*//; # no comments
>
>; s/^s+//; # no leading white
&gt;
> s/s+$//; # no trailing white
&gt;
> next unless length; # anything left?
&gt;
> 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
&gt; BSERVER'};port=$ConfigValue{'DBPORT'}&quot;;
>
> $db = DBI->connect($dns, $ConfigValue{'DBUSER'},
> $ConfigValue{'DBPASSWORD'});
>
>;
>
> if($db->;{'mysql_errno'})
&gt;
> {
>
> print ("<;br> Problem while connecting to database
> <br>$db->{'mysql_error'}");
>
&gt; }
>
> else
>;
> {
>
> print "Connected succesfully <br>";
&gt;
> $sql1=&quot;select * from second_level order by aler_id DESC";
>
> print "Query String : $sql1<br>";
>
> $exe=$db-&gt;prepare($sql1);
>
> if(!$exe-&gt;execute())
>
> {
>
> print "Problem while fetchingthe rows from
>; database&lt;br>$exe->{'mysql_error'}";
>
> }
>
> else
>;
> {
>
> print "Succesfully fetched rows from
>; database&lt;br>&quot;;
>;
> #row= $exe->fetchrow_array();
&gt;
> }
>
> }
>
>
>;
> Output observer on Command Line
>;
> ==================
>
>; -bash-3.00# perl displayalert.cgi
&gt;
> Content-Type: text/html
>
&gt;
>
> <br>before connecting<br>Connected succesfully <br>Query String : select
&gt; * from second_level order by aler_id DESC<br>Succesfully fetched rows
>; from database&lt;br>
>
>
>
&gt;
>
> Output observer on Web
>
> ===================
>
&gt;
> 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.
&gt;
>
>
>;
>
> Ramesh Polepalli
>
&gt;
>
>
>;
>
>
> mFormation Technologies Inc.
>; Direct Line: +91 80 6620 5939
>; Switchboard: +91 80 6620 5900
>;
> http://www.mformation.com
&gt;
>
>
>;
>
>
>
>
&gt;
>
> Visit WWW.MFORMATION.COM and see how the MFORMATION SERVICE MANAGER can
help you to transform your business.
>
&gt; [Non-text portions of this message have been removed]
>
>;
>
> Unsubscribing info is here:
http://help.yahoo.com/help/us/groups/groups-32.html
> Yahoo! Groups Links
&gt;
>
>

__._,_.___
.

__,_._,___
Re: Problem with perl CGI
country flaguser name
United States
2007-06-01 09:01:46

1) Does Apache have rights to read the file?

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

--- Ramesh Polepalli < ramesh.polepalli%40mformation.com">ramesh.polepallimformation.com>
wrote:

> Hi,
>
> I am new to perl CGI and writing a small web based
&gt; 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,
&gt;
>
>
> 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="&quot;;
&gt;
> my $sql1=&quot;";
>
> my $exe;
&gt;
> my %ConfigValue;
>
> my $returnstring="";
&gt;
>
>
>
>
> # Read the configuration from file to determine
> database credentials.
>
> my $cfgfile=&quot;./dbconnect";;
>
> open (CONFIG,$cfgfile);
>
>
>
> while (<CONFIG>) {
>
> chomp; # no newline
>
> s/#.*//; # no comments
>
> s/^s+//; # no leading white
&gt;
> s/s+$//; # no trailing white
&gt;
> next unless length; # anything left?
&gt;
> my ($var, $value) = split(/s*=s*/, $_, 2);
>
> $value=~ s/r//g;
>
> $ConfigValue{$var} = $value;
>
> }
>
> print "Content-Type: text/htmlnn";
>
>
>
> # connect to database
>
> my
>
$dns=&quot;DBI:mysql:database=$ConfigValue{'DBINSTANCE'};host=$ConfigValue{'D
&gt; BSERVER'};port=$ConfigValue{'DBPORT'}&quot;;
>
> $db = DBI->connect($dns, $ConfigValue{'DBUSER'},
> $ConfigValue{'DBPASSWORD'});
>
>
>
> if($db->;{'mysql_errno'})
&gt;
> {
>
> print ("<;br> Problem while connecting to
> database
> <br>$db->{'mysql_error'}");
>
> }
>
> else
>;
> {
>
> print "Connected succesfully <br>";
&gt;
> $sql1=&quot;select * from second_level order
&gt; by aler_id DESC";
>
> print "Query String : $sql1<br>";
>
> $exe=$db-&gt;prepare($sql1);
>
> if(!$exe-&gt;execute())
>
> {
>
> print "Problem while
&gt; fetchingthe rows from
>; database&lt;br>$exe->{'mysql_error'}";
>
> }
>
> else
>;
> {
>
> print "Succesfully fetched
> rows from
>; database&lt;br>&quot;;
>;
> #row=
>; $exe->fetchrow_array();
&gt;
> }
>
> }
>
>
>
> Output observer on Command Line
>;
> ==================
>
> -bash-3.00# perl displayalert.cgi
&gt;
> Content-Type: text/html
>
>
>
> <br>before connecting<br>Connected succesfully
> <br>Query String : select
&gt; * from second_level order by aler_id
> DESC<br>Succesfully fetched rows
>; from database&lt;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.
&gt;
>
>
=== message truncated ===

User Interface design blog
http://user-advocacy.blogspot.com/
Code:esign::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

__._,_.___
.

__,_._,___
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )