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ネイティブドライバーは、PHP5.3.3より前のSSLをサポートしていません。MySQL Native Driverは、PHP5.3以降のMicrosoftWindowsでデフォルトで有効になっています。
構文
オブジェクト指向スタイル:
$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);
?>
❮PHPMySQLiリファレンス