Funkce PHP mysqli ssl_set().
Příklad - Objektově orientovaný styl
Vytvořte připojení 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();
?>
Podívejte se na příklad procedurálního stylu dole.
Definice a použití
Funkce ssl_set() / mysqli_ssl_set() se používá k vytvoření zabezpečeného připojení pomocí SSL. Tato funkce však nedělá nic, pokud není povolena podpora OpenSSL.
Poznámka: Tato funkce musí být volána před real_connect() .
Poznámka: MySQL Native Driver nepodporuje SSL před PHP 5.3.3. Nativní ovladač MySQL je ve výchozím nastavení povolen na Microsoft Windows od PHP 5.3+.
Syntax
Objektově orientovaný styl:
$mysqli -> ssl_set(key, cert, ca, capath, cipher)
Styl postupu:
mysqli_ssl_set(connection, key, cert, ca, capath, cipher)
Hodnoty parametrů
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 |
Technické údaje
Návratová hodnota: | Vždy PRAVDA. Pokud je nastavení SSL nesprávné, vrátí real_connect() při pokusu o připojení chybu |
---|---|
Verze PHP: | 5+ |
Příklad - Procedurální styl
Vytvořte připojení 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);
?>
❮ Reference PHP MySQLi