dougao7801 2019-07-04 16:40
浏览 67
已采纳

PHP超时连接到Cloud SQL实例

Here is my code for PHP for connecting to the database, a Cloud SQL instance for MySQL:

define('DB_SERVER', '192.0.0.1');
define('DB_USERNAME', 'username');
define('DB_PASSWORD', 'password');
define('DB_NAME', 'db');

$db = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME) or die(mysqli_connect_error());

Obviously the DB_SERVER is not the actual IP address, nor are the credentials, but I did put in a dummy one to see if I needed to add anything like cloudsql:/ or jdbc:// like you do in Java.

I did authorize the IP address for the webserver on Cloud SQL, but all it returns is a Connection Timed Out error; What can I do to fix this?

I'm certain that the credentials are correct, and that I can connect from other authorized IP addresses, as I have been able to access from another account & multiple IP addresses through the MySQL workbench.

  • 写回答

1条回答 默认 最新

  • dousi1970 2019-07-06 13:33
    关注

    Solved:

    For anyone using Siteground's services, make sure to add 0.0.0.0/0 as the accepted IP addresses if you're using public IP authorization. Then find what IP's are connected when you refresh the php page by running this right after the page is refreshed:

    SELECT host FROM information_schema.processlist WHERE ID=connection_id();
    

    It should give you multiple IPs, and check them online using an IP locator to see if they match the location of the Siteground's services. Remove 0.0.0.0/0 and add that IP address to Google Cloud SQL.

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

报告相同问题?

悬赏问题

  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表