mysql connection failing as CGI
- From: ianatkinsonbsc@xxxxxxxxx
- Date: 21 Nov 2006 10:03:17 -0800
Hi,
I have a strange problem and I'm hoping someone can help. I've bought
some new hosting which comes with a MySQL database but I'm struggling
to get it working with any perl scripts; the hosting support are being
no help so I've had to come here, sorry guys!
The problem basically is that when the script is run as a CGI script it
won't connect to the database, however if I run the same script from
the command line (I have SSH access to the server) it runs fine.
The script is as follows (very simple):
--------------------------------------------------
#! /usr/bin/perl
use DBI;
print "Content-type: text/html\n\n";
print "<html><head></head><body>\n\nres:\n\n";
$dbh = DBI->connect('DBI:mysql:dbname:213.171.218.249:3306', 'dbuser',
'dbpass') || die "Content-type:text/html\n\ncon err!";
my $SQL = "SELECT * FROM numbers";
$sth = $dbh->prepare($SQL);
$sth->execute() || print "SQL Error on $SQL !!";
while (@row = $sth->fetchrow_array) { print @row; print "\n"; }
print "</body></html>";
--------------------------------------------------
And if I run it from the command line:
[domain1201232@ssh5 cgi-bin]$ perl numbers.pl
Content-type: text/html
<html><head></head><body>
res:
1
10
15
</body></html>
As you can see it connects to the database and retrieves the 3 ints sat
in there. If I run this from the CGI-bin however the only code output
is:
<html><head></head><body>
res:
i.e. the script falls over when it tries to make the database
connection and goes no further.
The hosting support are saying that I have not formed the connection
string properly, however if that was the case it wouldn't work from the
command line surely? I have also copied the script over to my machine
at home (verbatim and connecting to the same MySQL server) and it runs
fine from there also.
It seems to me like they have a firewalling problem maybe but I don't
have access to the Apache logs so I'm at a loss as to what else I can
try really. I did try the same thing in PHP (just using PHP syntax) and
that works OK, both on the command line and over the web which was
bringing me back round to the idea that it's a Perl problem, but I
really can't see anything wrong with it and if the syntax was wrong
it'd surely crap out on the command line as well!
Any ideas?
Thanks,
Ian.
.
- Follow-Ups:
- Re: mysql connection failing as CGI
- From: Ric
- Re: mysql connection failing as CGI
- From: Sherm Pendley
- Re: mysql connection failing as CGI
- Prev by Date: parsing from secure apache site. simple authentication
- Next by Date: Re: parsing from secure apache site. simple authentication
- Previous by thread: parsing from secure apache site. simple authentication
- Next by thread: Re: mysql connection failing as CGI
- Index(es):
Relevant Pages
|