0

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

Dharman
  • 30,962
  • 25
  • 85
  • 135
aman
  • 307
  • 21
  • 48
  • Don't picture text please. – dr0i Jun 23 '19 at 07:19
  • @dr0i there I have updated the question. please help me – aman Jun 23 '19 at 07:30
  • Good. Have a look at https://stackoverflow.com/questions/23581543/unable-to-access-google-cloud-sql-from-gae-sqlstatehy000-2002-unknown-erro , have you followed the advices? Don't use password, following https://developers.google.com/appengine/docs/php/cloud-sql/ ? – dr0i Jun 24 '19 at 07:11
  • Check also https://stackoverflow.com/questions/33522035/pdoexception-with-message-sqlstatehy000-2002-connection-timed-out-when-tr?rq=1. – dr0i Jun 24 '19 at 07:17

0 Answers0