Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DBI->connect

Status
Not open for further replies.

hut06

Programmer
Joined
Mar 19, 2007
Messages
3
Location
GB
Dear All,

I hope someone can help with this, its driving me insane:

I have a piece of code:

#!/usr/bin/perl

# PERL MODULES WE WILL BE USING
use DBI;

# HTTP HEADER
print "Content-type: text/html \n\n";

# CONFIG VARIABLES
$platform = "mysql";
$database = "database";
$host = "host";
$port = "port";
$tablename = "table";
$user = "user";
$pw = "password";

#DATA SOURCE NAME
$dsn = "dbi:mysql:$database:$host:3306";

# PERL DBI CONNECT (RENAMED HANDLE)
$dbstore = DBI->connect($dsn, $user, $pw) or die "Unable to connect: $DBI::errstr\n";


When run all I get is a blank screen, no errors or anything. So I printed a few lines to see where it was falling over. I can print a statement above "$dbstore = DBI->connect($dsn, $user, $pw) or die "Unable to connect: $DBI::errstr\n";"

but not below, meaning it must be falling over in this area. Any ideas would be welcome as to getting this script working.

Many thanks in advance

 
I assume your real config variables look different to this, and have real values in them. According to CPAN, the $dsn for the MySQL driver looks like
Code:
my $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";
Yours doesn't...

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::PerlDesignPatterns)[/small]
 
Sorry..

I have tried the $dsn like that aswell and I still only get a blank screen. Does anyone have any other ideas?

Thanks in advance for your reply
 
Are you running this from a terminal (or DOS prompt), or from a browser?

If it's in a browser, try running it in a terminal. It sounds like it's hanging when trying to connect, or you aren't getting the errors back in your browser.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::PerlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top