我尝试连接下面的cloud-sql,但它不起作用。谁能帮助我如何使用php连接Cloud sql?
我尝试了所有堆栈溢出的答案,但我无法找到解决方案
function connect() {
$hostname = null; //Defaults to mysqli.default_host
$username = "root";
$password = "";
$database = "db"; //Defaults to ""
$port = null; //Defaults to mysqli.default_port
$socket = "/cloudsql/Instance_connection_name";
// Connecting to mysql database
$this->conn =new mysqli($hostname, $username, $password, $database, $port, $socket);
// $mysqli->set_charset("utf8");
// Check for database connection error
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit;
}
// returing connection resource
return $mysqli;
}
}
这里我添加了错误
Warning: mysqli::__construct(): (HY000/2002): No such file or directory in /app/projectname/include/DbConnect.php on line 26 Failed to connect to MySQL: No such file or directory