I am a web developer who is having a hard time trying to get my scripts to connect to my new web host. The script works perfectly on my localhost (I'm using XAMPP) but once I try to use it on my web host, I get the following error:

Access denied for user 'ljvnxryi'@'server.nocdirect.in' (using password: YES)

I have changed all the information to what has been supplied by the web hosters but it is still not working. The strange bit is;
If I use a username/password combination (one specific) which was not given to me by the hosters, it lets me connect but won't let me select the database - it gives an access denied error on the selecting function.
If I use the username/password combination given to me by the hosters, I am unable to connect at all and get given the access denied error again.

Just in case anyone wants to check, here is the script I'm using to connect (with 'user', 'pass' and 'mydbname' replaced):
$con = mysql_connect('', 'user', 'pass') or die(mysql_error()); $db = mysql_select_db('mydbname') or die('Selection error:<br/>'.mysql_error());

Recommended Answers

All 4 Replies

Member Avatar

Does your DB allow you to access it from a remote site?
Many hosts disallow this as standard.

Can you log into your site's phpmyadmin with those credentials?

Thanks for the reply.

I think I have misled you a bit because the connection is an external IP instead of 'localhost'; I am trying to connect to it on the same site and the IP is what was given to me by the hosters.

I am able to log in to phpMyAdmin with the credentials.

Member Avatar

Yes, it's as I thought. Possible solution:

In cPanel, where you see MySQL


Then choose Remote Access...


Place your IP address in there. It should then let you connect from your local machine.

use the following code it may be helpful to you
// Check connection
if (mysqli_connect_errno())
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.