dongxu4023 2011-12-19 18:45
浏览 47
已采纳

无法在本地PHP测试环境中建立MySQL数据库连接

When I run the following page on my local development environment I'm getting a timeout error on the TCP connection. I've inherited this site recently from another developer. I've pulled all the files on the server and dropped them into my /Users/mycomputer/Sites/testsite.com folder on my MacBook Pro running Lion.

The code I'm running (obviously I've sanitized the code for posting here):

<?php
mysql_connect("mysqldb", "usernamehere", "passwordhere") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("test") or die(mysql_error());
echo "Connected to Database";
?>

And the error:

Warning: mysql_connect() [function.mysql-connect]: [2002] Operation timed out (trying to connect via tcp://mysqldb:3306) in /Users/mycomputer/Sites/testsite.com/dbtest.php on line 2
Warning: mysql_connect() [function.mysql-connect]: Operation timed out in /Users/mycomputer/Sites/testsite.com/dbtest.php on line 2
Operation timed out

Any ideas on where I've gone wrong? I'm pretty unskilled in the PHP world so, forgive my ignorance. If this were ColdFusion I would suspect a datasource problem.

  • 写回答

1条回答 默认 最新

  • douzhulan1815 2011-12-19 19:08
    关注

    Firstly, you need to check whether your website allows external IPs to connect to the DB. If they do, you might have to add your current IP to the list of allowed IPs.

    Then, you need to connect to the DB using their external db address. If you do all that correctly, this should work. You error shows that it can't connect to the DB.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号