PHP -zelfstudie

PHP HOME PHP-intro PHP-installatie PHP-syntaxis PHP-opmerkingen PHP-variabelen PHP-echo / afdrukken PHP-gegevenstypen PHP-strings PHP-nummers PHP-wiskunde PHP-constanten PHP-operators PHP Als...Anders...Anders PHP-switch PHP-loops PHP-functies PHP-arrays PHP Superglobals PHP RegEx

PHP- formulieren

PHP-formulierverwerking PHP-formuliervalidatie PHP-formulier vereist URL/e-mail van PHP-formulier PHP-formulier voltooid

PHP Geavanceerd

PHP-datum en tijd PHP opnemen PHP-bestandsverwerking PHP-bestand openen/lezen PHP-bestand maken/schrijven PHP-bestand uploaden PHP-cookies PHP-sessies PHP-filters PHP-filters geavanceerd PHP-callback-functies PHP JSON PHP-uitzonderingen

PHP OOP

PHP Wat is OOP PHP-klassen/objecten PHP-constructor PHP-vernietiger PHP-toegangsmodificaties PHP-overerving PHP-constanten PHP abstracte lessen PHP-interfaces PHP-kenmerken PHP statische methoden Statische eigenschappen van PHP PHP-naamruimten PHP-iterables

MySQL- database

MySQL-database MySQL Connect MySQL DB maken MySQL-tabel maken MySQL Gegevens invoegen MySQL Laatste ID ophalen MySQL Meerdere invoegen MySQL voorbereid MySQL Gegevens selecteren MySQL Waar MySQL Bestel op MySQL Gegevens verwijderen MySQL-updategegevens MySQL-limietgegevens

PHP XML

PHP XML-parsers PHP SimpleXML-parser PHP SimpleXML - Get PHP XML Expat PHP XML DOM

PHP - AJAX

Ajax-intro AJAX PHP AJAX-database AJAX XML Live zoeken in Ajax Ajax-peiling

PHP- voorbeelden

PHP-voorbeelden PHP-compiler PHP-quiz PHP-oefeningen PHP-certificaat

PHP- referentie

PHP-overzicht PHP-array PHP-agenda PHP-datum PHP-map PHP-fout PHP-uitzondering PHP-bestandssysteem PHP-filter PHP FTP PHP JSON PHP-sleutelwoorden PHP Libxml PHP-e-mail PHP-wiskunde PHP Diversen PHP MySQLi PHP-netwerk PHP-uitvoercontrole PHP RegEx PHP SimpleXML PHP-stream PHP-string Beheer van PHP-variabelen PHP XML-parser PHP-zip PHP-tijdzones

PHP mysqli options() Functie

❮ PHP MySQLi-referentie

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:
  • MYSQLI_OPT_CONNECT_TIMEOUT - Set connection timeout in seconds
  • MYSQLI_OPT_LOCAL_INFILE - Enable/Disable use of LOAD LOCAL INFILE
  • MYSQLI_INIT_COMMAND - Set a command to execute after connecting to MySQL server
  • MYSQLI_READ_DEFAULT_FILE - Set read options from named file instead of my.cnf
  • MYSQLI_READ_DEFAULT_GROUP - Set read options from named group from my.cnf or the file specified in MYSQLI_READ_DEFAULT_FILE
  • MYSQLI_SERVER_PUBLIC_KEY - Set RSA public key file used with SHA-256 based authentication
  • MYSQLI_OPT_NET_CMD_BUFFER_SIZE - only for mysqlnd
  • MYSQLI_OPT_NET_READ_BUFFER_SIZE - only for mysqlnd
  • MYSQLI_OPT_INT_AND_FLOAT_NATIVE - only for mysqlnd
  • MYSQLI_OPT_SSL_VERIFY_SERVER_CERT - only for mysqlnd
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