PHP -Tutorial

PHP-HOME PHP-Einführung PHP-Installation PHP-Syntax PHP-Kommentare PHP-Variablen PHP-Echo / Drucken PHP-Datentypen PHP-Strings PHP-Nummern PHP-Mathematik PHP-Konstanten PHP-Operatoren PHP If...Else...Elseif PHP-Schalter PHP-Schleifen PHP-Funktionen PHP-Arrays PHP-Superglobals PHP-RegEx

PHP -Formulare

Handhabung von PHP-Formularen PHP-Formularvalidierung PHP-Formular erforderlich PHP-Formular-URL/E-Mail PHP-Formular vollständig

PHP- Erweitert

PHP-Datum und -Zeit PHP einschließen Umgang mit PHP-Dateien PHP-Datei öffnen/lesen PHP-Datei erstellen/schreiben Hochladen von PHP-Dateien PHP-Cookies PHP-Sitzungen PHP-Filter PHP-Filter für Fortgeschrittene PHP-Callback-Funktionen PHP-JSON PHP-Ausnahmen

PHP -OOP

PHP Was ist OOP PHP-Klassen/Objekte PHP-Konstruktor PHP-Destruktor PHP-Zugriffsmodifikatoren PHP-Vererbung PHP-Konstanten Abstrakte PHP-Klassen PHP-Schnittstellen PHP-Eigenschaften Statische PHP-Methoden Statische PHP-Eigenschaften PHP-Namespaces PHP-Iterables

MySQL- Datenbank

MySQL-Datenbank MySQL Connect MySQL-DB erstellen MySQL-Tabelle erstellen MySQL-Daten einfügen MySQL Letzte ID abrufen MySQL Mehrfach einfügen MySQL vorbereitet MySQL Select-Daten MySQL-Wo MySQL-Reihenfolge nach MySQL-Daten löschen MySQL-Update-Daten MySQL-Limit-Daten

PHP- XML

PHP-XML-Parser PHP-SimpleXML-Parser PHP SimpleXML - Get PHP-XML-Expat PHP-XML-DOM

PHP -AJAX

AJAX-Einführung AJAX-PHP AJAX-Datenbank AJAX-XML AJAX Live-Suche AJAX-Umfrage

PHP- Beispiele

PHP-Beispiele PHP-Compiler PHP-Quiz PHP-Übungen PHP-Zertifikat

PHP- Referenz

PHP-Übersicht PHP-Array PHP-Kalender PHP-Datum PHP-Verzeichnis PHP-Fehler PHP-Ausnahme PHP-Dateisystem PHP-Filter PHP-FTP PHP-JSON PHP-Schlüsselwörter PHP-Libxml PHP-Mail PHP-Mathematik PHP-Sonstiges PHP MySQLi PHP-Netzwerk PHP-Ausgabesteuerung PHP-RegEx PHP-SimpleXML PHP-Stream PHP-String Umgang mit PHP-Variablen PHP-XML-Parser PHP-Zip PHP-Zeitzonen

PHP mysqli real_connect() Funktion

❮ PHP MySQLi-Referenz

Beispiel – Objektorientierter Stil

Öffnen Sie eine neue Verbindung zum MySQL-Server mit zusätzlichen Verbindungsoptionen:

<?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");
?> 

Sehen Sie sich das Beispiel für den prozeduralen Stil unten an.


Definition und Verwendung

Die Funktion real_connect() / mysqli_real_connect() öffnet eine neue Verbindung zum MySQL-Server.

Diese Funktion unterscheidet sich von connect() in folgenden Punkten:

  • real_connect() erfordert ein gültiges Objekt, das von init() erstellt wurde
  • real_connect() kann mit options() verwendet werden, um verschiedene Optionen für die Verbindung festzulegen
  • real_connect() hat einen Flag-Parameter

Syntax

Objektorientierter Stil:

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

Verfahrensstil:

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

Parameterwerte

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

Rückgabewert: TRUE auf Erfolg. FALSE bei Fehler
PHP-Version: 5+
PHP-Änderungsprotokoll: PHP 5.6: Flag MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT hinzugefügt

Beispiel – prozeduraler Stil

Öffnen Sie eine neue Verbindung zum MySQL-Server mit zusätzlichen Verbindungsoptionen:

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