PHP mysqli options() Functie
Voorbeeld - Objectgeoriënteerde stijl
Extra verbindingsopties instellen:
<?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");
?>
Kijk naar voorbeeld van procedurele stijl onderaan.
Definitie en gebruik
De functie options() / mysqli_options() wordt gebruikt om extra verbindingsopties in te stellen en het gedrag van een verbinding te beïnvloeden.
Opmerking: deze functie moet worden aangeroepen na init() en vóór real_connect() .
Syntaxis
Objectgeoriënteerde stijl:
$mysqli ->
options(option, value)
Procedurele stijl:
mysqli_options(connection, option, value)
Parameterwaarden
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
Winstwaarde: | WAAR op succes. ONWAAR bij fout |
---|---|
PHP-versie: | 5+ |
PHP-wijzigingslogboek: | PHP 5.5: MYSQLI_SERVER_PUBLIC_KEY-optie toegevoegd PHP 5.3: MYSQLI_OPT_INT_AND_FLOAT_NATIVE, MYSQLI_OPT_NET_CMD_BUFFER_SIZE, MYSQLI_OPT_NET_READ_BUFFER_SIZE en MYSQLI_IFERTY_SERVER_VERC-opties toegevoegd |
Voorbeeld - Procedurele stijl
Extra verbindingsopties instellen:
<?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-referentie