How to connect to Cloud SQL instance and insert values in a particular database from an external web application using PHP or Javascript?
Asked
Active
Viewed 262 times
-2
-
A bit more details would be welcome... – night-gold Jan 14 '19 at 15:58
-
I want to write a code in Javascript or PHP to connect to Cloud SQL instance and insert values in the particular database. – Chiro Jan 15 '19 at 11:40
-
Still lacking... From where do you want to connect? Do you know how to connect to a MySQL database with either javascript or php? – night-gold Jan 15 '19 at 13:13
-
I want to know how to connect to a Cloud SQL db with JS or PHP – Chiro Jan 16 '19 at 09:08
-
Yes... My question is still good... Are you in the same gcp project? Another gcp project? Do you know how to connect to a MySQL database with either JavaScript or PHP? Depending on what you say, my answer will not be the same... – night-gold Jan 16 '19 at 09:47
-
I know how to connect to a MySQL database. I am looking for how to connect to a Cloud SQL database. – Chiro Jan 16 '19 at 09:49
-
There you go, now from where do you connect? Same project or another? – night-gold Jan 16 '19 at 09:50
-
trying to do it in the same project – Chiro Jan 16 '19 at 09:53
1 Answers
0
The best way to connect to a CloudSQL instance inside the same gcp project is to use private ip, this way you won't need to use the CloudSQL proxy with a service account used to authenticate through the google API. That way is faster and more secure as you do not risk a mistake in the IAM.
To configurate private IP you juste need to follow this doc: https://cloud.google.com/sql/docs/mysql/configure-private-ip
Then you just have to connect to the CloudSQL instance using the IP as you would do for any other non local database.

night-gold
- 2,202
- 2
- 20
- 31
-
-
What do you mean connection string pattern? You use the account you created in your CloudSQL instance console to connect with the ip you created, same as any other database... – night-gold Jan 16 '19 at 10:07
-