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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem connecting to remote DB from CGI script. Please help. 1

Status
Not open for further replies.

MissouriTiger

Programmer
Oct 10, 2000
185
US
Please someone tell me if I'm doing something wrong.

I'm trying to connect to a remote database from a CGI script written in Perl. I keep getting a "cannot connect" error.

I've asked the host of the DB server to check the permissions, and if I'm using the right port #, and they say everything is fine.

I've tried this a million times. Any help is most welcome! Please have a look at my code below.

sub save_user_profile
{
my ($user, $password, $dsn, $dbHandle, $queryString, $stmtHandle);

$user = "norris";
$password = "secret";

#I tried the following line both with and without
#the port number.
$dsn = "DBI:mysql:norris:jlxlinux.com";
#Default port = 3306.

#Open connection to MySQL database.
$dbHandle = DBI->connect($dsn, $user, $password)
or die("Database connection error: $DBI::errstr");

#Create SQL statement.
$queryString = "INSERT INTO MEMBERS (User_ID, Password, First_Name, Last_Name, Email_Address) " +
" VALUES ($username, $password, $firstName, $lastName, $email);";

#Use statement handle to prepare and execute SQL statement.
$stmtHandle = $dbHandle->prepare($queryString);
$stmtHandle->execute
or die "Could not execute SQL statement ... maybe invalid?";

$stmtHandle->finish();
$dbHandle->disconnect();

}# End save_user_profile

If you think the problem is on their end, can anyone recommend a more reliable place to host my DB (free or cheap, since I'm just learning)?

Thanks in advance for any help/advice,

Greg _______________________________________
Constructed from 100% recycled electrons
 
1st, make syre you're calling DBI in your script: use DBI;

2nd, are you sure that you have access to MySql?

3rd: For a very good host - try FeaturePrice.com. $16.95/mo gets you unlimited bandwidth, unlimited email addresses, up to 4 virtual url's (yoursite.yoursite.com), every perl module you could think of, PHP, and MySql. Plus, the tech support is fast and fabulous. I sound like I own the place (I don't) but they've never let me down - not ONE time!!! There's always a better way...
 
Thanks a bunch for the advice! I have set up a new account and am successfully accessing my new DB. _______________________________________
Constructed from 100% recycled electrons
 
Glad all is working for you now. There's always a better way...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top