dongliang1873 2015-11-04 12:32
浏览 332

PDOException'与消息'SQLSTATE [HY000] [2002]连接超时'当试图连接到谷歌云sql

Hie members
so I was trying to connect to Google cloud sql from an external site

I authorized the ip of the server in google cloud at Instance -> Access Control -> Authorization

and the instance also has been assigned an IP lets say 'X.X.X.X', and a user also has been created with User name 'username' and password 'password'

now the connection code for connecting google cloud sql I used is as follows

$db = new pdo('mysql:host=X.X.X.X;dbname=db','username','password');

and I tried opening the page and I am getting the following error

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] Connection timed out' in /home/kannadakavana/public_html/test.php:17 Stack trace: #0 /home/kannadakavana/public_html/test.php(17): PDO->__construct('mysql:host=X....', 'username', '') #1 {main} thrown in /home/kannadakavana/public_html/test.php on line 17

what am I doing wrong ?

  • 写回答

2条回答 默认 最新

  • douhuang3833 2015-11-04 18:37
    关注

    By default Cloud SQL instances does not have IPv4 enable.

    Did you enable IPv4 address? It is under Access Control > IP address tab.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog