mysql connection failing as CGI



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.

.



Relevant Pages

  • RE: problem with DBD::Oracle
    ... Next, if it runs from the command line, then you most likely have a permissions issue with either the Perl script itself, or the Oracle.so library. ... Oracle database that is on a different machine. ... sender of the delivery error by replying to this message, or notify us by ...
    (perl.dbi.users)
  • Re: mysql connection failing as CGI
    ... 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 ... The problem basically is that when the script is run as a CGI script it ... the command line it runs fine. ...
    (comp.lang.perl.misc)
  • Re: How do I Edit a list of files associated with a product ?
    ... So it succesfully adds the product and the files in a database and the filesystem. ... and you have done something like that or you know a url or script that does that, ... Just build an edit command with the selected file name and ... you better check out the syntax for the exec command since it has additional parameters. ...
    (comp.lang.php)
  • Re: php script to create mySQL database programmatically
    ... hosting configuration may not allow create database from script, ... Need working code to create database programmatically via PHP. ... Are you running this on the server with MySQL installed? ...
    (comp.lang.php)
  • Re: sanitizing uploaded data with a form
    ... i'm escaping quotes for the database, but i wasn't sure what other ... If the script is to display them, ... especially someone else on the server, if you use a shared server and ... Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers ...
    (alt.php)