PHP mysqli opsies() Funksie
Voorbeeld - Objekgeoriënteerde styl
Stel ekstra verbinding opsies:
<?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");
?>
Kyk na voorbeeld van prosedurele styl onderaan.
Definisie en gebruik
Die opsies() / mysqli_options()-funksie word gebruik om ekstra verbindingsopsies te stel en gedrag vir 'n verbinding te beïnvloed.
Let wel: Hierdie funksie moet na init() en voor real_connect() genoem word .
Sintaksis
Objekgeoriënteerde styl:
$mysqli ->
options(option, value)
Prosedure styl:
mysqli_options(connection, option, value)
Parameterwaardes
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 |
Tegniese besonderhede
Terugkeerwaarde: | WAAR oor sukses. ONWAAR op mislukking |
---|---|
PHP weergawe: | 5+ |
PHP Changelog: | PHP 5.5: Bygevoeg MYSQLI_SERVER_PUBLIC_KEY opsie PHP 5.3: Bygevoeg MYSQLI_OPT_INT_AND_FLOAT_NATIVE, MYSQLI_OPT_NET_CMD_BUFFER_SIZE, MYSQLI_OPT_NET_READ_BUFFER_SIZE, en_SSERQLI_VERCIFTY opsies |
Voorbeeld - Prosedurele styl
Stel ekstra verbinding opsies:
<?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-verwysing