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 real_connect() Functie

❮ PHP MySQLi-referentie

Voorbeeld - Objectgeoriënteerde stijl

Open een nieuwe verbinding met de MySQL-server, met extra verbindingsopties:

<?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 real_connect() / mysqli_real_connect() opent een nieuwe verbinding met de MySQL-server.

Deze functie verschilt van connect() op de volgende manieren:

  • real_connect() vereist een geldig object gemaakt door init()
  • real_connect() kan worden gebruikt met options() om verschillende opties voor de verbinding in te stellen
  • real_connect() heeft een vlagparameter

Syntaxis

Objectgeoriënteerde stijl:

$mysqli -> real_connect(host, username, password, dbname, port, socket, flag)

Procedurele stijl:

mysqli_real_connect(connection, host, username, password, dbname, port, socket, flag)

Parameterwaarden

Parameter Description
connection Required. Specifies the MySQL connection to use
host Optional. Specifies a host name or an IP address
username Optional. Specifies the MySQL username
password Optional. Specifies the MySQL password
dbname Optional. Specifies the default database to be used
port Optional. Specifies the port number to attempt to connect to the MySQL server
socket Optional. Specifies the socket or named pipe to be used
flag Optional. Specifies different connection options. Possible values:
  • MYSQLI_CLIENT_COMPRESS - Use compression protocol
  • MYSQLI_CLIENT_FOUND_ROWS - Return number of matched rows (not affected rows)
  • MYSQLI_CLIENT_IGNORE_SPACE - Allow spaces after function names. Make function names reserved words
  • MYSQLI_CLIENT_INTERACTIVE - Allow interactive_timeout seconds of inactivity before closing connection
  • MYSQLI_CLIENT_SSL - Use SSL encryption
  • MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT

Technische details

Winstwaarde: WAAR op succes. ONWAAR bij fout
PHP-versie: 5+
PHP-wijzigingslogboek: PHP 5.6: MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT-vlag toegevoegd

Voorbeeld - Procedurele stijl

Open een nieuwe verbinding met de MySQL-server, met extra verbindingsopties:

<?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