[英]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.