Ant Ant - 2 months ago 13
MySQL Question

Not able to connect to DB when site uploaded to Plesk Panel

So, I have a very simple php configuration file to connect to a MySQL Database, called

connect.php
inside a folder called
modules
, which is included in all the pages that require access to the Database.
I have a user (let's call him
db_user
) created with the database (let's call it
db1
) from within my plesk panel.
Now when I try to access a database, through a custom login page that simply checks
db1
to see is username and password are a match, I get the following error logs:


[Wed Jun 11 23:21:59 2014] [warn] [client 1.2.3.4] mod_fcgid: stderr: PHP Warning: mysql_connect(): Access denied for user 'db_user'@'localhost' (using password: YES) in /var/www/vhosts/~sitename~/httpdocs/modules/connect.php on line 2, referer: http:// ~sitename~/admin/login

[Wed Jun 11 23:21:59 2014] [warn] [client 1.2.3.4] mod_fcgid: stderr: PHP Warning: mysql_select_db(): Access denied for user ''@'localhost' (using password: NO) in /var/www/vhosts/~sitename~/httpdocs/modules/connect.php on line 3, referer: http:// ~sitename~/admin/login

[,,,] (more messages essentially saying it has not connected and as a result are trying to connect with no username and password)


The
connect.php
file is:

<?php
mysql_connect('localhost', 'db_user', 'password');
mysql_select_db("db1");
?>


Here are the
SHOW GRANTS FOR db_user@'%';


##Grants for db_user@%##
`GRANT USAGE ON *.* TO 'db1'@'%' IDENTIFIED BY PASSWORD '*BEE6E9D5D5A3C2E1EC93EBCA0E4E527C0328BE01'`

GRANT ALL PRIVILEGES ON `db_user`.* TO 'db1'@'%'


Mind that everything is running smoothly on my MAMP configuration back at my workstation, so I doubt there is any code related issue.
So, I have run out of ideas on what I could try to solve this...
Any suggestion would be very appreciated!

Ant Ant
Answer

Apparently in the database section there is a column named Database server which gives the address of the database, which in my case simply was not localhost, 127.0.0.1 or anything like that!

I changed the address and off it worked!