دالة 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