简体   繁体   English

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

[英]Can't access database on my server

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. 我创建了一个用户和一个数据库,但似乎无法用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. 相同的代码正在与我的其他服务器hungergamesportugal.com一起使用,但是我似乎无法将sql文件上传到该数据库(它说我没有权限...我不知道为什么),然后继续该服务器允许我导入sql文件,但似乎无法访问数据库。

Can someone please help? 有人可以帮忙吗? :/ :/

You're using the wrong port. 您使用了错误的端口。 2082 is for cPanel. 2082适用于cPanel。 3306 is for MySQL (usually). 3306通常用于MySQL。

Generally, you can omit the port entirely: 通常,您可以完全省略端口:

$host = 'anapaiva.pt';

You also need to assign the connect function to a variable: 您还需要将connect函数分配给一个变量:

$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. 您可以使用cpanel允许权限,向远程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. 单击后,您可以添加IP地址以允许数据库权限。 This may help you. 这可能对您有帮助。 search remote database at cpanel. 在cpanel中搜索远程数据库。 May be this help you, http://forums.cpanel.net/f354/enable-remote-access-customer-database-251951.html 可能对您有帮助, http://forums.cpanel.net/f354/enable-remote-access-customer-database-251951.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM