无法通过GAE访问Google Cloud SQL:"SQLSTATE [HY000] [2002]未知错误4294967295". [英] Unable to access Google Cloud SQL from GAE: "SQLSTATE[HY000] [2002] Unknown error 4294967295"

查看:101
本文介绍了无法通过GAE访问Google Cloud SQL:"SQLSTATE [HY000] [2002]未知错误4294967295".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个显示教师电子邮件的程序.这些老师的姓名和电子邮件都在数据库中.

I'm trying to create a program that shows the emails of teachers. The name and emails of these teachers are in a database.

我从Google那里获取了示例代码并对其进行了修改,但是它似乎不起作用.我也无法解决该错误,因为给出的消息是未知错误". 我应该如何调试/修复此错误?

I took the sample code from Google and modified it, but it does not seem to work. I am also unable to resolve the error, as the message given is "Unknown error". How should I go about to debug / fix this error?

我已经重新启动了sql server,并尝试了许多方式来调整代码,但是它似乎不想给我我的结果:(我也将gae应用程序也添加到了数据库的应用程序列表中

I have restarted the sql server, and tried tweaking the code in many many ways, but it doesn't seem to want to give me my result :( I have added the gae app to the applications list for the database as well.

相关代码段位于此处:

为了安全起见,我更改了代码,以使IP为111.111.111.111,数据库为db.

For security, I have changed the code so that the IP is 111.111.111.111 and the database is db.

<h2>Teachers:</h2>
  <?php
  // Create a connection.

  $db = null;
  if (isset($_SERVER['SERVER_SOFTWARE']) &&
  strpos($_SERVER['SERVER_SOFTWARE'],'Google App Engine') !== false) {
    // Connect from App Engine.
    try{
       $db = new PDO('mysql:host=111.111.111.111:3306;dbname=db', 'root', 'password');
    }catch(PDOException $ex){
        die(json_encode(
            array('outcome' => false, 'message' => 'Unable to connect.', 'error' => $ex->getMessage())
            )
        );
    }
  }

  try {
    // Show existing guestbook entries.
    foreach($db->query('SELECT * from db.teacher') as $row) {
            echo "<div><strong>" . $row['title'] . " " .$row['name'] . "</strong> has email <br> " . $row['email'] . "</div>";
     }
  } catch (PDOException $ex) {
    echo "An error occurred.";
  }
  $db = null;
  ?>

当我访问网站时,这就是我的问候:

When I go to the website, this is what I am greeted with:

Teachers:

{"outcome":false,"message":"Unable to connect.","error":"SQLSTATE[HY000] [2002] Unknown error 4294967295"}

谢谢!

推荐答案

您无需指定IP地址

$db = new pdo('mysql:unix_socket=/cloudsql/<your-project-id>:<your-instance-name>;dbname=<database-name>',
  'root',  // username
  ''       // password
  );

https://developers.google.com/appengine/docs/php /cloud-sql/

如果您的应用程序和数据库连接正确(您已授予该GAE应用程序访问该Google SQL数据库的权限,等等),则它应该正常工作".

If your app and DB are connected properly (you have given permission to that GAE app to access that Google SQL database etc) then it should "just work".

如果要通过IP连接,则必须进入实例并手动为其提供IP地址.

If you want to connect by IP you have to go in to the instance and give it an IP address manually.

这篇关于无法通过GAE访问Google Cloud SQL:"SQLSTATE [HY000] [2002]未知错误4294967295".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆