Monday, March 14, 2016

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

Kevin, I think it worked. Will do more testing and update you

2016/03/14 18:56:37 Got a connection for "<your-project-id>:<the-region>:<your-instance-name>"
2016/03/14 18:56:37 from "<your-project-id>:<the-region>:<your-instance-name>" via IP:3307: read tcp IP->IP:3307: use of closed network connection

But two things: 

1. What is really the purpose of CREATE USER name_of_user@'cloudsqlproxy~%';  in your documentation. I'm still a bit confused about it? I should be able to login using regular mysql username and password from php right Or I need to have that?
2.  How do I silent the print out from proxy and how can I keep the command running even after server reboot?


On Monday, March 14, 2016 at 6:30:12 PM UTC-4, Kevin Malachowski wrote:
What does the proxy print out after you try to connect using PHP?

Can you try running the proxy with the following commands?

sudo ./cloud_sql_proxy -dir=/cloudsql -instances="<your-project-id>:<the-region>:<your-instance-name>" -credential_file=/root/developmentDB.json


On Monday, March 14, 2016 at 2:20:44 PM UTC-7, 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/30b588f4-ae80-4ebb-bbe9-5f3f825e1100%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment