我是 php 新手,我正在尝试使用 ssl 连接到 gloudsql 证书。但它给了我一个关于CN的错误。什么意思 我的代码中缺少什么?我的项目名称是wiiboardtest
,我的 实例名称为personal
$key = 'C:/Users/tasne/Downloads/client-key.pem';
$cert = 'C:/Users/tas/Downloads/client-cert.pem';
$ca = 'C:/Users/tas/Downloads/server-ca (1).pem';
$con = mysqli_init();
if(!$con){
die("mysqli_init failed");
}
$trial =
mysqli_ssl_set($con,$key,$cert,$ca,NULL,'ECDHE-RSA-AES256-SHA');
mysqli_options($con,
MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, false);
$dbhost = '35.246.68.234';
$dbuser = 'root';
$dbpass = 'waffer';
$database = 'personal';
$port = '3306';
$conn=mysqli_real_connect($con,$dbhost,$dbuser,$dbpass,$database,$port,
MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT );
if(!$conn){
die("connect error due
to:".mysqli_connect_error());
};
mysqli_real_connect((: 对等证书 CN=
wiiboardtest:personal' did not match expected CN=
35.246.68.234'
问题是你的函数参数不正确。mysqli_real_connect
需要 8 个参数,您传递了 7 个参数,这意味着flags
参数用于socket
。
更改此行:
$conn=mysqli_real_connect($con,$dbhost,$dbuser,$dbpass,$database,$port,MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT);
对此:
$conn=mysqli_real_connect($con,$dbhost,$dbuser,$dbpass,$database,$port,NULL,MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT);