Mysql connection error


#1

Hi,

When I try to connect to my database from a PHP script I get the followng error;

Warning: mysql_connect() [function.mysql-connect]: Access denied for user ‘user’@‘ip-xxx-xx-xxx-xx.dreamhost.com’ (using password: YES) in /home/.nocturne/user/demo.mydomain.com/inc/conf.php on line 10
error

On line 10, I’ve written mysql_connect(“db.mydomain.com”, “user”, “password”) or die(“error”);

I can connect locally machine using EMS SQL Manager, because I entered my local ip address in “From what hosts (computers) may myuser connect to these databases”, but my script cannot connect to mysql. “%.dreamhost.com” also exists in “From what hosts (computers) may parskunt connect to these databases” section.

I dont know what to do. Any help will be appriciated.
Thanks…


#2

Are you sure you are using the correct host name for your database, and not the database name?

For instance, if I have a database named “db”, I cannot connect to it via the code you posted by using “db.mydomian.com”; I have to connect to using “hostname.mydomain.com”. You can view the hostname a database is assigned to in the Control Panel–>goodies–Manage MySQL. By default, Dreamhost usually assigns “mysql.mydomain.com” as a host unless you name it differently or create an additional host (alias).

I suggest you double check for the correct hostname usage, as I suspect that is where your problem lies (given, of course, that your user/pass is correct :wink: ). Good luck, and let us know if that was, in fact the problem, ok?

–rlparker


#3

Thanks for your reply,

I’ve setup wordpress from “one-click installs” section and it works fine. My db server name is “db.parskunt.com” and I can connect it with phpmyadmin.

Wordpress config is;

define(‘DB_NAME’, ‘parsblog’);
define(‘DB_USER’, ‘parskunt’);
define(‘DB_PASSWORD’, ‘XXXXXXXXXXXXXXX’);
define(‘DB_HOST’, ‘db.parskunt.com’);

I use the same host, user, and password from Wordpress config file, I only change the database name, but I cannot connect to my db.

Wordpress mysql connection is
define(‘DB_NAME’, ‘parsblog’);
define(‘DB_USER’, ‘parskunt’);
define(‘DB_PASSWORD’, ‘XXXXXXXXX’);
define(‘DB_HOST’, ‘db.parskunt.com’);
@mysql_connect($dbhost, $dbuser, $dbpassword);

while mine is
$hostname = “db.parskunt.com”;
$username = “parskunt”;
$password = “XXXXXXXXXX”;
$database = “parskunt”;
mysql_connect($hostname, $dusername, $password);

Thanks…


EDIT: I’ve solved the problem. I’ve “defined” all 4 variables then the problem is gone;

define(‘DB_HOSTNAME’, ‘db.parskunt.com’);
define(‘DB_USERNAME’, ‘parskunt’);
define(‘DB_PASSWORD’, ‘XXXXXXXXXX’);
define(‘DB_DATABASE’, ‘parskunt’);
mysql_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD)

I dont know why this is the way it works but that solved my problem.


#4

Looks like your problem had to do with using double quotes on the hostname. The host name had periods in it, so it should have used single quotes.
Silk

My website