PHP mysqli options() Funktion
Beispiel – Objektorientierter Stil
Legen Sie zusätzliche Verbindungsoptionen fest:
<?php
$mysqli = mysqli_init();
if (!$mysqli) {
die("mysqli_init failed");
}
// Specify connection timeout
$con -> options(MYSQLI_OPT_CONNECT_TIMEOUT, 10);
// Specify read options from named file instead of my.cnf
$con ->
options(MYSQLI_READ_DEFAULT_FILE, "myfile.cnf");
$con -> real_connect("localhost","my_user","my_password","my_db");
?>
Sehen Sie sich das Beispiel für den prozeduralen Stil unten an.
Definition und Verwendung
Die Funktion options() / mysqli_options() wird verwendet, um zusätzliche Verbindungsoptionen festzulegen und das Verhalten für eine Verbindung zu beeinflussen.
Hinweis: Diese Funktion sollte nach init() und vor real_connect() aufgerufen werden .
Syntax
Objektorientierter Stil:
$mysqli ->
options(option, value)
Verfahrensstil:
mysqli_options(connection, option, value)
Parameterwerte
Parameter | Description |
---|---|
connection | Required. Specifies the MySQL connection to use |
option | Required. Specifies the option to set. Can be one of the following values:
|
value | Required. Specifies the value for the option |
Technische Details
Rückgabewert: | TRUE auf Erfolg. FALSE bei Fehler |
---|---|
PHP-Version: | 5+ |
PHP-Änderungsprotokoll: | PHP 5.5: Option MYSQLI_SERVER_PUBLIC_KEY hinzugefügt PHP 5.3: Optionen MYSQLI_OPT_INT_AND_FLOAT_NATIVE, MYSQLI_OPT_NET_CMD_BUFFER_SIZE, MYSQLI_OPT_NET_READ_BUFFER_SIZE und MYSQLI_OPT_SSL_VERIFY_SERVER_CERT hinzugefügt |
Beispiel – prozeduraler Stil
Legen Sie zusätzliche Verbindungsoptionen fest:
<?php
$con = mysqli_init();
if (!$con) {
die("mysqli_init failed");
}
// Specify connection timeout
mysqli_options($con,
MYSQLI_OPT_CONNECT_TIMEOUT, 10);
// Specify read options from named file instead of my.cnf
mysqli_options($con, MYSQLI_READ_DEFAULT_FILE, "myfile.cnf");
mysqli_real_connect($con,"localhost","my_user","my_password","my_db");
?>
❮ PHP MySQLi-Referenz