Re: mysql connection failing as CGI



ianatkinsonbsc@xxxxxxxxx schrieb:
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.


Can you check apache log?

tail -f /var/log/http/error_log

you may find the apache log somewhere else depending on your OS.
In addition to that I would use eval to find out what went wrong, see below

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";

my $SQL;
my $dbh;
my $sth;

eval{
$dbh =
DBI->connect("DBI:mysql:dbname:mydbname;host=213.171.218.249;port=3306",
"dbuser","dbpass",
{
RaiseError => 1
}
);


$SQL = "SELECT * FROM numbers";

$sth = $dbh->prepare($SQL);
$sth->execute();
};
if($@){
print $@;
}
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)
  • 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: Oracle database not starting up after reboot on RedHat ES4 Linux !
    ... I have Oracle database enterprise edition 9.2.0.4 running on RedHat ... I am using dbstart command via a /etc/init.d/oracle file. ... When working with shell scripts that are executed by cron or on system startup, it is often useful to run those scripts in a manner that does not have your environment included in the execution of that script. ...
    (comp.databases.oracle.server)