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

MySQL Problem

Status
Not open for further replies.

BenRussell

Programmer
Joined
Mar 12, 2001
Messages
243
Location
US
I am having problems connecting to the a MySQL server. It gives me the error "Access denied: Anakin@localhost".
I use the following code :

--------------
use DBI;

# Declare variables
$DB_Name = "tibsun_Test";
$DB_User = "Anakin";
$DB_Pass = "password";
$dsn = "DBI:mysql:$DB_Name";
$dbh = DBI->connect('$dsn','$DB_Use','$DB_Pass') || die "Couldnt connect to database";
return;
---------------

Something wrong with it?
That is just the connect part, there is more to it after that. - Ben Russell
- President of Intracor Technologies (
 
You are using single quotes to surround your connect parameters - single quotes do *NOT* allow variable interpolation. Trying using double quotes to surround those parameters, like:

$dbh = DBI->connect("$dsn","$DB_User","$DB_Pass") || die "Couldnt connect to
database";

HTH.
Hardy Merrill
Mission Critical Linux, Inc.
 
When I connect to mysql I use the following dsn:
Code:
my $dsn = "DBI:mysql:database=$DB_Name;host=localhost;port=3306";
I'm not sure how much difference leaving off host and port makes, they probably default to localhost and 3306. Also the "database=" part may not be required, but it couldn't hurt.

I also don't use quotes in the connect statement at all, I don't think they are needed:
Code:
$dbh = DBI->connect($dsn, $DB_User, $DB_Pass) || die(DBI::errstr);
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top