Tuesday, July 26, 2016

Re: [google-cloud-sql-discuss] Trying to Connect to database in PHP using PDO and Cloud SQL Proxy

I am having the same issue. I followed all the instructions on this page https://cloud.google.com/sql/docs/compute-engine-access and I am able to connect with mysql -u root -p -S /cloudsql/projectid:region:instance and confirm with show databases;. Now my issue when I connect with the PDO I get :

SQLSTATE[HY000] [2002] Permission denied

The DSN I am trying to connect with is mysql:unix_socket=/cloudsql/<projectid>:<region>:<instance>;dbname=<dbname>;charset=utf8. 

How did you get this to work? I am trying to get this to work with PDO. I am using CentOS.

Thanks


On Monday, March 14, 2016 at 5:20:44 PM UTC-4, wob...@yblew.com wrote:
I double checked and it's still not working. I can connect to it using mysql on the command line but not via PHP/PDO

On Monday, March 14, 2016 at 4:41:10 PM UTC-4, Vadim Berezniker wrote:
Can you double check the instance connection string?
You should use the value that is shown as the "instance connection string" on the instance page in the Developer Console.

instance_name.png

On Mon, Mar 14, 2016 at 9:48 AM <wob...@yblew.com> wrote:
 sudo ./cloud_sql_proxy -dir=/cloudsql -fuse -credential_file=/root/developmentDB.json &
[1] 31266
[root@dev /]# 2016/03/14 12:46:39 couldn't unmount fuse directory "/cloudsql": &errors.errorString{s:"exit status 1: fusermount: failed to unmount /cloudsql: Invalid argument"}
2016/03/14 12:46:39 Mounting "/cloudsql"...
2016/03/14 12:46:39 Mounted "/cloudsql"
2016/03/14 12:46:39 Socket prefix: /cloudsql



On Monday, March 14, 2016 at 12:40:43 PM UTC-4, Vadim Berezniker wrote:
What is the command you are using to start the proxy?

On Mon, Mar 14, 2016 at 9:31 AM <wob...@yblew.com> wrote:
ls /cloudsql give me README.

I changed the socket name to "project_id:region:instance_name. " but no luck 

On Monday, March 14, 2016 at 12:25:13 PM UTC-4, Vadim Berezniker wrote:
Where are you running your application? On your local machine?

The socket name should be project_id:region:instance_name. 
You should be able to run "ls /cloudsql" and see the sockets there.

On Mon, Mar 14, 2016 at 9:19 AM <wob...@yblew.com> wrote:
I tried to connect  to database in  PHP using PDO and Cloud SQL Proxy but have no luck. I keep getting 



Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory'

Im using

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
$pdo = new PDO('mysql:unix_socket=/cloudsql/<your-project-id>:<your-instance-name>;dbname=db'
'db', 
'db'
);
$statement = $pdo->query("SHOW TABLES;");
$row = $statement->fetch(PDO::FETCH_ASSOC);
echo htmlentities($row['_message']);
?>

Has anyone had any luck connecting

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/411eb6c1-fafa-4613-812d-b36728f447d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/02317d1f-a4d1-467e-bff3-2132901a0ded%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/ce76a1fc-2c41-4a64-ae8d-9f9279ecf8e0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/cc44fd8b-6f15-492c-98c4-2ce31010b085%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment