php - Google-App-Engine MySQL datebase not connecting -


i have google app engine website php , mysql instance database attached. have database connection file , can connect database website in gae development area when deploy application unaware of how connect them. have following code doesn't work.

<?php   $host = "unix_socket=/cloudsql/application:instancename";   $user = "root";   $password = "password";   $database = "database";    $connect = new mysqli($host, $user, $password, $database );     if ($connect->connect_errno)    {     echo "failed connect mysql: " . $connect->connect_error;    } ?> 

any ideas?

let's follow along guidance @ https://cloud.google.com/appengine/docs/php/cloud-sql/ ...

i imagine you've followed https://cloud.google.com/appengine/docs/php/cloud-sql/#create including confirmation of grant of access cloud sql instance app engine app via latter's application id (and they're in same geographical region, &c -- detailed there , @ links therefrom).

now, if want use app engine app msqli, @ example @ page...:

$sql = new mysqli(null,   'root', // username   '',     // password   <database-name>,   null,   '/cloudsql/<your-project-id>:<your-instance-name>'   ); 

see many differences? first argument null, password empty string, , cloud sql reference sixth argument.

alternatively, if you've purchased ip address cloud sql instance, example @ same url is

$sql = new mysqli('127.0.0.1:3306',   '<username>',   '<password>',   <database-name>   ); 

but think former approach preferred (and saves modest expense ip address -- don't let example mislead you, ip address use not 127.0.0.1, whatever had purchased cloud sql instance:-).

yes, different mix needed access mysql local development server deployed appspot.com app -- recommend read through example @ url i've given see how turn advantage (using local mysql on development machine when you're developing locally, , reserving actual cloud sql instance deployed apps -- way, bugs might have during local development won't break real database , cause problems!-)


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -