I have created a Google Cloud SQL Instance but I cannot figure out how to connect with it through php. I am not able to connect to my Cloud Instance through PDO or mysqli_connect in a php file stored on a local Xampp Server. Please Help I keep on receiving a error. I'm struggling a lot. I have given some details below, if more are required please let me know.
Database Name: test_database.
Instance User: test_user & pass.
Google Cloud SQL Instance Info:
Public IP address: 35.244.68.115
Instance connection name: test-244508:australia-southeast1:test
test.php:
<?php
$dsn = "mysql:host=35.244.68.115;dbname=test_database;unix_socket=/cloudsql/test-244508:australia-southeast1:test";
$user = "test_user";
$password = "pass";
$pdo = new PDO($dsn, $user, $password);
// OR
$mysqli_conn = mysqli_connect("35.244.68.115", "test_user", "pass", "test_database");
?>
error:
Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\xampp\htdocs\test\test.php:19 Stack trace: #0 C:\xampp\htdocs\test\test.php(19): PDO->__construct('mysql:host=35.2...', 'test_user', 'pass') #1 {main} thrown in C:\xampp\htdocs\test\test.php on line 19