Mysql_connect problem

I’m trying to connect to mysql by reading hostname, username, and password from an .inc file, but, I’m having a little difficulty.

If I connect using the following format:

$host = ‘’;
$user = ‘username’;
$pass = ‘password’;
$name = ‘dbname’;

$db = mysql_connect($host,$user,$pass);

…I get access denied error. But, If I connect using the code below:

$host = ‘’;
$user = ‘username’;
$name = ‘dbname’;

$db = mysql_connect($host,$user,‘password’);

…it works.

So, the code breaks if I use the variable $pass. I made sure that $pass has the right value with no leading or trailing spaces. Please help. Thank you.

Does the value of $pass happen to change anywhere after you defined it? That’s the only thing I can think of.

Nope, it does not change at all. That page is the only page where I’m using $pass. There are no other pages on my site that use that variable.

I have always had success doing it like this:

[code]// initialize database variables
$hostname = “”;
$username = “username”;
$password = “password”;
$database = “dbname”;

// connect to database
$link = mysql_connect($hostname,$username,$password);
mysql_select_db($database);[/code]Once the link has been established, there is no need to specify the database connection when choosing a database.

Simon Jessey
Keystone Websites | si-blog

I’m so sorry for troubling. I had my password wrong. :embarrased: