无法访问我的服务器上的数据库

I am having some problems with my database. I created a user, and a database, but I can't seem to access it with php.

My code is:

$host = 'anapaiva.pt:2082';
$user = 'anapaiva_p1';
$pass = 'xxxx';
$db = 'anapaiva_mcmm1';

@mysql_connect($host, $user, $pass) or die('err: '.mysql_error());
@mysql_select_db($db) or die('err: '.mysql_error());

And on the webpage, appears the following errors:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'anapaiva_p1'@'apollo' (using password: YES) in /home/anapaiva/public_html/mcmm/connection/dbconn.php on line 6

Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in /home/anapaiva/public_html/mcmm/connection/dbconn.php on line 7

The same code was working with my other server, hungergamesportugal.com, but I can't seem to upload the sql file to that database (it says I don't have permissions... I don't know why), and on this server it allows me to import the sql file, but I can't seem to access the database.

Can someone please help? :/

You're using the wrong port. 2082 is for cPanel. 3306 is for MySQL (usually).

Generally, you can omit the port entirely:

$host = 'anapaiva.pt';

You also need to assign the connect function to a variable:

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

So that you can close the connection when you're done with it:

mysql_close($dh);
  • Test same user on localhost
    $mysql_host = "localhost";
    $mysql_database = "db_name";
    $mysql_user = "root";
    $mysql_password = "password";

    $con = mysql_connect($mysql_host,$mysql_user, $mysql_password);
    mysql_select_db($mysql_database, $con);

OR

You can allow permission using cpanel, add permission to remote mysql. I don't remember exact name, but it was something like, remote database. on clicking you can add ip address to allow database permission. This may help you. search remote database at cpanel. May be this help you, http://forums.cpanel.net/f354/enable-remote-access-customer-database-251951.html