Reputation: 61
I´m trying to connect Cloud SQL with App engine this way
<?php
class ConectorBD{
private $host = 'localhost';
private $user = 'first_user';
private $password = '12345';
private $port = null;
private $socket = '/cloudsql/instance-name';
private $connect;
function initConnect($name_db){
$this->connect = new mysqli($this->host, $this->user, $this->password, $name_db, $this->port, $this->socket);
if ($this->connect ->connect_error) {
return "Error:" . $this->conexion->connect_error;
}else {
return "OK";
}
}
}
$con = new ConectorBD();
echo $con->initConnect('my_db');
?>
But the next error appear Error:MySQL server has gone away
Upvotes: 2
Views: 530
Reputation: 36
To get the connection name open Cloud Shell and run command below
gcloud sql instances describe instance-name
$conn = new PDO("mysql:unix_socket=/cloudsql/project_id:sql_instance_region:intance_id;dbname=db_name", "root", "your_root_password");
$mysqli = mysqli_connect(null, "root" , "your_root_password", 'db_name', null, '/cloudsql/project_id:sql_instance_region:intance_id');
Upvotes: 2