我已经创建了一个Google Cloud SQL Instance
,但是我不知道如何通过php
与它连接。我无法通过PDO
或mysqli_connect
连接到存储在本地php
上的Xampp Server
文件中的云实例。请帮助我继续收到错误消息。我很努力。我在下面提供了一些详细信息,如果需要更多信息,请告诉我。
数据库名称:test_database
。
实例用户:test_user
和pass
。
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