PHP mysqli ssl_set()ฟังก์ชั่น
ตัวอย่าง - สไตล์เชิงวัตถุ
สร้างการเชื่อมต่อ SSL:
<?php
$mysqli = mysqli_init();
if (!$mysqli) {
die("mysqli_init failed");
}
$mysqli -> ssl_set("key.pem", "cert.pem", "cacert.pem", NULL, NULL);
if (!$mysqli -> real_connect("localhost","my_user","my_password","my_db"))
{
die("Connect Error: " . mysqli_connect_error());
}
// Some queries...
$mysqli -> close();
?>
ดูตัวอย่างรูปแบบขั้นตอนที่ด้านล่าง
ความหมายและการใช้งาน
ฟังก์ชัน ssl_set() / mysqli_ssl_set() ใช้เพื่อสร้างการเชื่อมต่อที่ปลอดภัยโดยใช้ SSL อย่างไรก็ตาม ฟังก์ชันนี้ไม่ทำอะไรเลยเว้นแต่จะเปิดใช้งานการสนับสนุน OpenSSL
หมายเหตุ:ต้องเรียกใช้ฟังก์ชันนี้ก่อน real_connect( )
หมายเหตุ: MySQL Native Driver ไม่รองรับ SSL ก่อน PHP 5.3.3 MySQL Native Driver ถูกเปิดใช้งานโดยค่าเริ่มต้นบน Microsoft Windows จาก PHP 5.3+
ไวยากรณ์
สไตล์เชิงวัตถุ:
$mysqli -> ssl_set(key, cert, ca, capath, cipher)
รูปแบบขั้นตอน:
mysqli_ssl_set(connection, key, cert, ca, capath, cipher)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
connection | Required. Specifies the MySQL connection to use |
key | Required. Specifies the path name to the key file |
cert | Required. Specifies the path name to the certificate file |
ca | Required. Specifies the path name to the certificate authority file |
capath | Required. Specifies the pathname to a directory that contains trusted SSL CA certificates in PEM format |
cipher | Required. Specifies a list of allowable ciphers to use for SSL encryption |
รายละเอียดทางเทคนิค
คืนมูลค่า: | จริงเสมอ หากการตั้งค่า SSL ไม่ถูกต้อง real_connect()จะส่งคืนข้อผิดพลาดเมื่อคุณพยายามเชื่อมต่อ |
---|---|
รุ่น PHP: | 5+ |
ตัวอย่าง - รูปแบบขั้นตอน
สร้างการเชื่อมต่อ SSL:
<?php
$con = mysqli_init();
if (!$con) {
die("mysqli_init failed");
}
mysqli_ssl_set($con, "key.pem", "cert.pem", "cacert.pem", NULL, NULL);
if (!mysqli_real_connect($con, "localhost", "my_user", "my_password", "my_db")) {
die("Connect Error: " . mysqli_connect_error());
}
// Some queries...
mysqli_close($con);
?>
❮ PHP MySQLi อ้างอิง