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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度