I can easily connect to a remote MySQL server using the DBI module in my Perl scripts. However, when I try to use the same connection settings/properties from within a CGI script, the connection fails.
There are no helpful errors/warnings being logged either in the apache error log, or the browser, in spite of using
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
Strangely, the exact same script works fine when executed from the terminal. I also tried connecting the CGI script to the MySQL server on localhost, but without any success.
On the other hand, phpMyAdmin works great on the machine.
I'm using CentOS Release 5.8. I'm suspecting it is a system/priveleges issue with the apache user or anywhere else on the OS, but have hit a dead end.
Any pointers would be much appreciated!
Thanks a lot.
Edit: I'm using the following connection string
$dbh = DBI->connect($ds, $uname, $pwd,{RaiseError => 1 }) or die "$DBI::errstr Could not connect: $!<br>";
sudo -u <apache user> <your script>. If it fails, that will be much easier to debug. Also, if there are no errors or warnings, how do you know the connection failed?Software error: DBI connect('$dbname:$host:$port','$username',...) failed: Can't connect to MySQL server on '$host' (13) at /var/www/cgi-bin/crm/$scriptname.cgi line 24Not sure what to make out of that. Thanks$dbname:$host:$portand$usernamein the error string? Try printing out$ds,$unameand$pwd. I think they don't contain what you think they contain. I think you have a single quote somewhere you should have a double.