PHP handleiding

PHP TUIS PHP Inleiding PHP installeer PHP sintaksis PHP opmerkings PHP veranderlikes PHP Echo / Druk PHP datatipes PHP Strings PHP-nommers PHP Wiskunde PHP konstante PHP-operateurs PHP As...Anders...Elseif PHP skakelaar PHP-lusse PHP funksies PHP-skikkings PHP Superglobals PHP RegEx

PHP- vorms

PHP-vormhantering PHP-vorm validering PHP-vorm word vereis PHP-vorm URL/e-pos PHP-vorm voltooi

PHP Gevorderd

PHP datum en tyd PHP sluit in PHP-lêerhantering PHP-lêer oop/lees PHP-lêer skep/skryf PHP-lêer oplaai PHP-koekies PHP-sessies PHP filters PHP-filters Gevorderd PHP-terugbelfunksies PHP JSON PHP-uitsonderings

PHP OOP

PHP Wat is OOP PHP Klasse/Objekte PHP Konstrukteur PHP vernietiger PHP Toegangswysigers PHP erfenis PHP konstante PHP Abstrakte Klasse PHP-koppelvlakke PHP eienskappe PHP statiese metodes PHP Statiese Eienskappe PHP naamruimtes PHP Iterables

MySQL- databasis

MySQL-databasis MySQL Connect MySQL Skep DB MySQL Skep tabel MySQL Voeg data in MySQL Kry Laaste ID MySQL Voeg veelvuldige in MySQL voorberei MySQL Kies Data MySQL Waar MySQL Bestel deur MySQL verwyder data MySQL-opdateringsdata MySQL-limietdata

PHP XML

PHP XML-ontleders PHP SimpleXML-ontleder PHP SimpleXML - Kry PHP XML Expat PHP XML DOM

PHP - AJAX

AJAX Intro AJAX PHP AJAX-databasis AJAX XML AJAX Live Search AJAX-peiling

PHP voorbeelde

PHP voorbeelde PHP samesteller PHP vasvra PHP Oefeninge PHP-sertifikaat

PHP- verwysing

PHP Oorsig PHP Skikking PHP-kalender PHP datum PHP gids PHP fout PHP-uitsondering PHP lêerstelsel PHP filter PHP FTP PHP JSON PHP sleutelwoorde PHP Libxml PHP-pos PHP Wiskunde PHP Diverse PHP MySQLi PHP-netwerk PHP-uitsetbeheer PHP RegEx PHP SimpleXML PHP-stroom PHP-string PHP veranderlike hantering PHP XML-ontleder PHP zip PHP Tydsones

PHP mysqli real_connect() Funksie

❮ PHP MySQLi-verwysing

Voorbeeld - Objekgeoriënteerde styl

Maak 'n nuwe verbinding met die MySQL-bediener oop, met ekstra verbindingsopsies:

<?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 real_connect() / mysqli_real_connect() funksie maak 'n nuwe verbinding met die MySQL-bediener oop.

Hierdie funksie verskil van connect() op die volgende maniere:

  • real_connect() vereis 'n geldige voorwerp geskep deur init()
  • real_connect() kan gebruik word met opsies() om verskillende opsies vir die verbinding te stel
  • real_connect() het 'n vlagparameter

Sintaksis

Objekgeoriënteerde styl:

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

Prosedure styl:

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

Parameterwaardes

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

Tegniese besonderhede

Terugkeerwaarde: WAAR oor sukses. ONWAAR op mislukking
PHP weergawe: 5+
PHP Changelog: PHP 5.6: Bygevoeg MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT vlag

Voorbeeld - Prosedurele styl

Maak 'n nuwe verbinding met die MySQL-bediener oop, met ekstra verbindingsopsies:

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