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 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决