简体   繁体   English

无法使用PHP访问我的AWS托管数据库

[英]Can't access my AWS hosted database using PHP

I am having a huge issue with accessing my AWS database from within the php code for a site i am building. 从正在构建的站点的php代码中访问我的AWS数据库时,我遇到了一个很大的问题。 I have tried many different connection methods, and all seem to give an error that says 我尝试了许多不同的连接方法,但似乎都给出了错误提示

    Warning: mysqli_connect(): (HY000/2003): Can't connect to MySQL server on '(the endpoint of my hosted DB)' (111)

I've looked up error 111, but I can not seem to understand why it applies to me in this scenario. 我查找了错误111,但似乎无法理解为什么在这种情况下它适用于我。 I can access my database from any computer, using the same information I'm using here to try to connect. 我可以使用与此处尝试连接时使用的相同信息,从任何计算机上访问数据库。 I'm starting to think it's the host I'm using for my site that's the problem. 我开始认为这是我的网站所使用的主机。 I'm using the free biz.nf host just for testing, but I'm not sure my site host really should have any effect on the php inside my site. 我正在使用免费的biz.nf主机进行测试,但是我不确定我的站点主机是否真的会对站点内部的php产生任何影响。 Here's my connect statement 这是我的连接语句

    $mysql_host="DB endpoint";
    $mysql_user="myusername";
    $mysql_pass="mypassword";
    $my_db="myDBname";

    $con = mysqli_connect($mysql_host,$mysql_user,$mysql_pass);

    if (mysqli_connect_errno())
    {
         echo "Failed to connect to MySQL: " . mysqli_connect_error();
    } 

Thanks for the help! 谢谢您的帮助!

You likely need to update your security group and route tables for your subnets to allow the host on biz.nf to access the RDS instance. 您可能需要更新子网的安全组和路由表,以允许biz.nf上的主机访问RDS实例。

Check your RDS dashboard for the given instance, and examine the settings on your security group and subnets. 检查给定实例的RDS仪表板,并检查安全组和子网上的设置。

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

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