i'm new at Google Cloud and need help to connect my PHP App Engine in Standard Enviroment with Google Cloud SQL (MySQL). They are in the same region and the connect from MySQL Workbench works. In the Workbench i use the public ip from the Google SQL instance. But MySQLi gives me the error: "Connection refused". I tried it with PDO too and it gives me the same error.
Thats my PHP Code:
<?php
$host = '127.0.0.1';
$user = 'root';
$dbpassword = 'password';
$database = 'database';
$port = 3306;
$mysqli = new mysqli($host, $user, $dbpassword, $database, $port);
if ($mysqli->connect_errno) {
die("Verbindung fehlgeschlagen: ".$mysqli->connect_error);
}
And thats the app.yaml:
runtime: php72
handlers:
- url: /css
static_dir: css
- url: /src
static_dir: src
- url: /js
static_dir: js
beta_settings:
cloud_sql_instances: "project:europe-west3:instanceid=tcp:3306"
I hope anyone can help me. Thanks.
Edit: I also tried:
$mysqli = new mysqli(null, $user, $dbpassword, $database, null, "/cloudsql/{connectionstring}");
if ($mysqli->connect_errno) {
die("Verbindung fehlgeschlagen: ".$mysqli->connect_error);
}
And it gives me: "No such file or directory"