phpmysqlmysql-select-dbremote-host

Unable to select database(remote)


every time I try to connect to database, I get this message database select error .Access denied for user '<username>'@'localhost' to database '<database>' . My site is hosted remotely . To connect to database , my connect.php is like :

    $host = 'localhost';
    $user = '<username>';
    $pass = '<password>';
    $db = '<database>';

    $conn = mysql_connect($host,$user,$pass) or die('Unable to connect to host ');

    @mysql_select_db($db,$conn) or die('database select error .'.mysql_error());

I have cross checked the username and password,its correct and I have given all the privileges to the user <username> .

Whats going wrong ?


Solution

  • Most likely, the server on which the database is hosted it set to refuse connections from any request that doesn't originate from a white-listed source. This is particularly true if you're accessing a database on a shared-hosting plan, such as a Hostmonster, 1&1, etc. plan.

    If it's not a shared host, you need to change "localhost" to be the IP and port number of the server+MySQL port,