GAE PHP won't connect to Cloud SQL

久未见 提交于 2019-12-13 00:11:09

问题


Can't seem to get GAE PHP to connect to Cloud SQL, using mysqli, says: Unable to find the socket transport "unix" - did you forget to enable it when you configured PHP?

I've authorized the app and made sure they're both in the same region i.e US

any ideas would be great, thanks

$mysqli = new mysqli(null, "USERNAME", "PASSWORD", "DATABASE", null,
"/cloudsql/PROJECT_NAME:db2");

when i use :/cloudsql/PROJECT_NAME:db2 it's saying there's error with 'sock'

When i use /cloudsql/PROJECT_NAME:db2 without : it's saying cannot connect to user@localhost


回答1:


If you are using default authentication, try using “root” as the username, null as password, and the instance-id listed in the Cloud SQL panel, like so. Example:

$conn = new mysqli(null, "root", null, "<databasename>", null, "/cloudsql/<instance id>”);



回答2:


In case anyone viewing this post and getting the 'Unable to find the socket transport "unix"'(that was me) and is using PDO instead of sqli, here is the proper code.

$db = new pdo("mysql:unix_socket=/cloudsql/$GAE_ProjectName:$location:$dbInstance;dbname=$dbName",$username,$password)

These, /cloudsql/$GAE_ProjectName:$location:$dbInstance, can all be found together and copy pasted from the dashboard of your SQL instance under "Connect to this instance" and then "Instance connection name."

The rest of it is just defining those variables and making sure the passwords are right!



来源:https://stackoverflow.com/questions/21921855/gae-php-wont-connect-to-cloud-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!