Re: mysql connection failing as CGI
- From: Sherm Pendley <spamtrap@xxxxxxxxxxx>
- Date: Tue, 21 Nov 2006 13:23:24 -0500
ianatkinsonbsc@xxxxxxxxx writes:
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 strict;
use warnings;
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!";
Well, the first thing to do is ask Perl what went wrong:
my $dbh = DBI->connect('...');
if ( $dbh->err ) {
print 'DBI Error: ', $dbh->errstr, '<br>';
exit;
}
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:
When a database connection succeeds for one user but fails for another, the
most common cause is that the server account has a different level of access
to the database. For instance, the web server process may be running inside
of a chroot "jail" in which /tmp/mysql.sock isn't visible.
There are any number of guesses I could give you though - Asking the database
handle for its error string will tell you for certain what went wrong.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
.
- Follow-Ups:
- Re: mysql connection failing as CGI
- From: ianatkinsonbsc
- Re: mysql connection failing as CGI
- References:
- mysql connection failing as CGI
- From: ianatkinsonbsc
- mysql connection failing as CGI
- Prev by Date: Using a variable in a matching string
- Next by Date: Re: DOS-Box script is running in set always on top
- Previous by thread: mysql connection failing as CGI
- Next by thread: Re: mysql connection failing as CGI
- Index(es):
Relevant Pages
|