duanjianao0592 2013-05-17 17:19
浏览 372
已采纳

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

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? :/

  • 写回答

3条回答 默认 最新

  • douli2063 2013-05-17 17:21
    关注

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料