PHP mysqli ssl_set() Funksie
Voorbeeld - Objekgeoriënteerde styl
Skep 'n SSL-verbinding:
<?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();
?>
Kyk na voorbeeld van prosedurele styl onderaan.
Definisie en gebruik
Die ssl_set() / mysqli_ssl_set() funksie word gebruik om veilige verbindings met behulp van SSL te vestig. Hierdie funksie doen egter niks tensy OpenSSL-ondersteuning geaktiveer is nie.
Let wel: Hierdie funksie moet geroep word voor real_connect() .
Let wel: MySQL Native Driver ondersteun nie SSL voor PHP 5.3.3 nie. MySQL Native Driver is by verstek geaktiveer op Microsoft Windows vanaf PHP 5.3+.
Sintaksis
Objekgeoriënteerde styl:
$mysqli -> ssl_set(key, cert, ca, capath, cipher)
Prosedure styl:
mysqli_ssl_set(connection, key, cert, ca, capath, cipher)
Parameterwaardes
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 |
Tegniese besonderhede
Terugkeerwaarde: | Altyd WAAR. As SSL-opstelling verkeerd is, sal real_connect() 'n fout terugstuur wanneer jy probeer koppel |
---|---|
PHP weergawe: | 5+ |
Voorbeeld - Prosedurele styl
Skep 'n SSL-verbinding:
<?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-verwysing