简体   繁体   English

无法从Google App Engine灵活环境PHP项目连接到Cloud SQL实例

[英]Cannot connect to cloud sql instance from google app engine flexible environment PHP project

i am trying to deploy a test php project on google app engine flexible environment. 我正在尝试在Google App Engine灵活环境上部署测试php项目。

My app.yaml looks like this: 我的app.yaml看起来像这样:

* *

runtime: php
env: flex
service: testphpflex
manual_scaling:
  instances: 1
#[START cloudsql_settings]
# Use the connection name obtained when configuring your Cloud SQL instance.
beta_settings:
    cloud_sql_instances: "my-first-project:us-central1:tempdb"
#[END cloudsql_settings]

* *

The composer.json looks like this: composer.json如下所示:

{
    "require": {
        "silex/silex": "^1.3",
        "php": "5.6.*",
        "google/apiclient": "^2.0"

    },
    "require-dev": {
        "google/cloud-tools": "^0.6",
        "paragonie/random_compat": "^2.0",
        "phpunit/phpunit": "~4"
    }
}

And my sample code looks like this: 我的示例代码如下所示:

<?php
 $conn = mysql_connect('unix_socket:/cloudsql/my-first-project:us-central1:tempdb',
         'username', 
         'password'
     );

     echo "<br><br/>connection done";
if(!$conn)
{
die('Connection Failed'.mysql_error());
}
else 
{
die('Connection successful');
}

?>

However, i am not able to connect. 但是,我无法连接。 What is wrong? 怎么了?

My hypothesis is that the Google Cloud SQL API is not enabled. 我的假设是未启用Google Cloud SQL API。

Go to the following link and see if it's enabled. 转到以下链接,查看是否已启用。 Enable it if not. 如果没有启用它。

https://console.cloud.google.com/apis/api/sqladmin.googleapis.com/overview?project=_ https://console.cloud.google.com/apis/api/sqladmin.googleapis.com/overview?project=_

Then try re-deploying the app (unfortunately you need to deploy it again). 然后尝试重新部署该应用程序(不幸的是,您需要再次部署它)。 If this is the case, it's a dup of Connecting to 2nd gen Cloud SQL on App Engine flexible PHP 7.0 - missing socket 在这种情况下,这是在App Engine flexible PHP 7.0上连接到第二代Cloud SQL的双重方式-缺少套接字

Google Cloud Support tells me that mysql_connect is deprecated. Google云端支持告诉我mysql_connect已过时。 It has been deprecated in PHP since 5.5 and so there is no support for this. 自5.5起,PHP就已弃用该功能,因此不支持此功能。 So the above is not supported. 因此不支持以上内容。

I think I understand why you're getting the error. 我想我理解您为什么会收到错误消息。

You should use: 您应该使用:

mysql_connect(':/cloudsql/my-first-project:us-central1:tempdb',

or 要么

mysql_connect('localhost:/cloudsql/my-first-project:us-central1:tempdb',

According to the manual http://php.net/manual/en/function.mysql-connect.php 根据手册http://php.net/manual/en/function.mysql-connect.php

暂无
暂无

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

相关问题 Google App Engine-使用mysqli用php连接到SQL Cloud实例 - Google App Engine - Connect to SQL Cloud Instance with php using mysqli 无法从App Engine应用程序(灵活的环境)PHP连接到MySQL第二代实例 - Unable to connect to a MySQL Second Generation instance from an App Engine application (flexible environment) PHP 在 Google App Engine 柔性环境 PHP (Laravel) 上启用 CORS - Enabling CORS on Google App Engine Flexible environment PHP (Laravel) Google App Engine灵活PHP环境中服务器之间的会话 - Session between servers in Google App Engine Flexible PHP environment MAMP尝试连接到生产SQL数据库-本地主机PHP Google App Engine Flexible无法正常工作 - MAMP attempting to connect to production SQL Database - localhost PHP Google App Engine Flexible Not Working 我可以从App Engine中托管的PHP应用程序连接Google Cloud SQL吗? - Can I connect Google Cloud SQL from PHP application Hosted in App Engine? 应用引擎无法连接到Google云sql - App engine fails to connect to Google cloud sql 从 Cloud Run PHP 连接到 Google Cloud Compute Engine 虚拟机上的 MySQL 实例 - Connect to MySQL instance on Google Cloud Compute Engine VM from Cloud Run PHP 无法使用 laravel 应用程序和 unix 套接字从应用程序引擎 php 标准环境连接到云 mysql - Can't connect to cloud mysql from app engine php standard environment with laravel app and unix socket 无法使用ZF2中的Pdo_Mysql通过Google App Engine连接到Google Cloud SQL - Cannot connect to Google Cloud SQL through Google App Engine with Pdo_Mysql in ZF2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM