PHP mysqli ssl_set() İşlevi
Örnek - Nesne Yönelimli stil
Bir SSL bağlantısı oluşturun:
<?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();
?>
En alttaki prosedürel stil örneğine bakın.
Tanım ve Kullanım
SSL kullanarak güvenli bağlantılar kurmak için ssl_set() / mysqli_ssl_set() işlevi kullanılır. Ancak, OpenSSL desteği etkinleştirilmedikçe bu işlev hiçbir şey yapmaz.
Not: Bu fonksiyon real_connect() 'den önce çağrılmalıdır .
Not: MySQL Native Driver, PHP 5.3.3'ten önce SSL'yi desteklemez. MySQL Yerel Sürücüsü, PHP 5.3+ sürümünden itibaren Microsoft Windows'ta varsayılan olarak etkinleştirilmiştir.
Sözdizimi
Nesne yönelimli stil:
$mysqli -> ssl_set(key, cert, ca, capath, cipher)
Prosedür stili:
mysqli_ssl_set(connection, key, cert, ca, capath, cipher)
Parametre Değerleri
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 |
Teknik detaylar
Geri dönüş değeri: | Herzaman doğru. SSL kurulumu yanlışsa, bağlanmaya çalıştığınızda real_connect() bir hata döndürür |
---|---|
PHP Sürümü: | 5+ |
Örnek - Prosedür stili
Bir SSL bağlantısı oluşturun:
<?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 Referansı