cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Go to solution

Perl DBI Module Issue on CGI

Hi,

 

  Sorry if I double posted.  My question earlier seems to have vanished all of a sudden after I edited a word in it.  Anyway, as the title explains, I have a script that connects to a database.  It works for most of my servers, but it fails on Godaddy's hosting. 

 

  The issue is the error logs are nowhere to be found so I'm shooting blindly basically so I decided to break down the script.  As you can see from screenshot below, the script runs fine if you execute it via shell, but if through CGI, it just breaks at connect. 

  I also tried backticks instead and ran it from a separate script. Same thing as soon as it goes through CGI, it breaks at connect. Screenshot and edited code below.

  Apache issue?  Any ideas?  Any help would be much appreciated. 

#!/usr/bin/env perl
print "Content-type: Text/plain\n\n";

use DBI;
use JSON;
use Data::Dumper;

my $dbh;
my $sth;
my $query;
my $dsn='dbi:mysql:dbnamehere:localhost:3306';

sub DBCon(){
print "connecting\n";
my $user='usernamehere';
my $pass = 'passhere';
$dbh = DBI->connect($dsn, $user, $pass,  { RaiseError => 1, AutoCommit => 1 }) || print "Error -> DBI::errstr";
print Dumper $dbh;
$sth=$dbh->prepare("USE dbnamehere");
$sth->execute();
}

        print "Before con\n";
	DBCon;
	print "after con\n";
	my $x = QLog($mail,$to,$subject,$body);
	print "After query - $x\n";
	DBClose;
	print "Closing\n";

screenshot.pngbrowser.png

 

1 REPLY 1
Solution

Re: Perl DBI Module Issue on CGI

Never mind. All sorted. Changed the shebang line to

#!/usr/bin/perlml