Gossamer Forum
Home : General : Perl Programming :

DBI connection "error"

Quote Reply
DBI connection "error"
  

HELP! When I try to connect to my database I am getting the following "error." (I used quotes for a reason) When I run my script from a command prompt, it connects to the database and returns all rows exactly as expected. When I run it from a web browser, though, I get the following error message:

Can't call method "prepare" on an undefined value at C:\cgi-bin\returnauction.cgi line 7.

This is my DBI initialization:
$database = DBI->connect ("DBI:ODBC:AuctionData",{PrintError => 1, RaiseError => 1});


I don't understand how the connection to my database can be OK when run from a prompt, but be undefined when run from a browser. Any help is very much appreciated as I think that Google is getting tired of spitting out worthless results to my requests. Thanks.

--Seth

Quote Reply
Re: [seth_h] DBI connection "error" In reply to
You don't seem to be using a username/password. This works just fine for me;

Code:
my $dbh = DBI->connect ("DBI:mysql:database_name:localhost", "user", "pass", {PrintError => 0, RaiseError => 1}) or die print "Cannot connect to database: ", $!;

my $sth= $dbh->prepare ("SELECT * FROM Countries");
$sth->execute();
while (my $hit = $sth->fetchrow_hashref()) {
print $hit->{Name} . "<BR>";
}

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!