致命错误:未捕获的PDOException:与Google Cloud SQL实例连接

时间:2019-06-23 05:47:20

标签: php pdo

我已经创建了一个Google Cloud SQL Instance,但是我不知道如何通过php与它连接。我无法通过PDOmysqli_connect连接到存储在本地php上的Xampp Server文件中的云实例。请帮助我继续收到错误消息。我很努力。我在下面提供了一些详细信息,如果需要更多信息,请告诉我。

数据库名称:test_database

实例用户:test_userpass


Google Cloud SQL Instance Info:

公共IP地址:35.244.68.115

实例连接名称: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

0 个答案:

没有答案