问题描述
我在连接到App引擎(Java运行时)中托管的Cloud SQL实例时遇到问题.连接客户端是另一个Google应用程序引擎实例中托管的PHP Web应用程序. App Engine实例是否可以连接到另一个实例中的Cloud SQL?
I am experiencing issues connecting to a Cloud SQL instance hosted in an App engine (Java Runtime). The connecting client is a PHP web application hosted in another Google app engine instance. Is it possible for an App engine instance to connect to a Cloud SQL in another instance?
基本上,我的设置如下:
Basically, my setup is as follow:
- Google App Engine 1(Java运行时)
- 已安装Cloud SQL实例
- 托管Google端点并在此实例上连接到Cloud SQL
- Google App Engine 1 (Java Runtime)
- installed with Cloud SQL instance
- hosts Google Endpoints and connects to Cloud SQL on this instance
- 连接到Google App Engine 1的Cloud SQL实例的PHP脚本
问题是我总是在下面出现错误:
The problem is I am always getting error below:
Warning: mysqli_connect(): MySQL server has gone away in /base/data/home/apps/s~some-php-web-app-v1/v1.376456666740733344/includes/database.php on line 29 Warning: mysqli_connect(): Error while reading greeting packet. PID=-1
我认为我的连接代码正确
I believe that my connection code is correct
public function connect($server = DBHOST, $username = DBUSER, $password = DBPASS, $database = DBNAME, $socket = DBSOCKET, $port = DBPORT) { $this->link = mysqli_connect($server, $username, $password, $database, $port, $socket) or die(mysqli_error()); }
常量是:
define('DBHOST', null); define('DBSOCKET','/cloudsql/some-app-v1-test:some-db'); define('DBNAME', 'database_name'); define('DBUSER', 'root'); define('DBPORT', null); define('DBPASS', null); define('PROJECT_PATH', "http:someserver.com//");
这可能吗?如果是这样,我必须设置什么配置才能使其正常工作?
Is this possible? If it is, what configuration do I have to set in order to make this work?
谢谢,斯蒂芬
推荐答案
我找到了新手问题的答案.在Cloud SQL控制台上单击编辑",然后在授权的App Engine应用程序"部分下添加Google应用实例ID.
I found the answer to my novice question. Click Edit on your Cloud SQL console then add your google app instance id under "Authorized App Engine Applications" section.
这篇关于从PHP App Engine实例连接到在另一个运行Java Runtime的App Engine中创建的Cloud SQL实例的连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!