需要将我的App Engine PHP与我的Google Cloud SQL数据库连接起来 [英] Need help connecting my App Engine PHP with my Google Cloud SQL Database

查看:142
本文介绍了需要将我的App Engine PHP与我的Google Cloud SQL数据库连接起来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的php脚本的sql连接代码,因为它试图连接到我的Google SQL云数据库

 < ?php 

$ con = mysqli_connect(:/ cloudsql / projectID:google-cloud-instance,root,root,DATABASE);
//检查连接
if(mysqli_connect_errno())
{
echo糟糕!一定是错误的?:。 mysqli_connect_error()
;`

但是当我处理整体php脚本时,我得到以下错误:

 php_network_getaddresses:gethostbyname failed。errno = 0Error:
pre>

我是这个的初学者,所以如果有人能帮助我..


  1. 了解这意味着什么

  2. 我可以如何修复?

需要帮助!

解决方案

您需要将云SQL实例名作为'socket'参数传递给MySQLi 构造函数。例如

  $ instance_name =:/ cloudsql / projectID:google-cloud-instance; 
$ c = new mysqli(null,$ username,$ password,$ database,0,$ instance_name);

如果您使用默认身份验证(应用程序级身份验证),那么您可以传递root和无密码

  $ instance_name =:/ cloudsql / projectID:google-cloud-instance; 
$ c = new mysqli(null,root,,$ database,0,$ instance_name);


Below is the sql connection code for my php script as it attempts to connect to my Google SQL Cloud Database

<?php

$con=mysqli_connect(":/cloudsql/projectID:google-cloud-instance","root","root","DATABASE");
// Check connection
if (mysqli_connect_errno())
{
echo "Oops! Something Must Have Went Wrong?: " . mysqli_connect_error()
;`

but when I process the overall php script i get the following error:

"php_network_getaddresses: gethostbyname failed. errno=0Error:"

I am a beginner at this, so if someone can help me..

  1. Understand what this means
  2. How the heck can I fix?

Thanks in Advance for the help!

解决方案

You need to pass the cloud SQL instance name as the 'socket' parameter to the MySQLi constructor. For example

$instance_name = ":/cloudsql/projectID:google-cloud-instance";
$c = new mysqli(null, $username, $password, $database, 0, $instance_name);

if you're using the default auth (application level auth) then you can pass root and no password to connect.

$instance_name = ":/cloudsql/projectID:google-cloud-instance";
$c = new mysqli(null, "root", "", $database, 0, $instance_name);

这篇关于需要将我的App Engine PHP与我的Google Cloud SQL数据库连接起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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