Tutoriel PHP

ACCUEIL PHP Introduction PHP Installation PHP Syntaxe PHP Commentaires PHP Variables PHP Écho PHP / Impression Types de données PHP Chaînes PHP Numéros PHP Mathématiques PHP Constantes PHP Opérateurs PHP PHP Si... Sinon... Sinon Commutateur PHP Boucles PHP Fonctions PHP Tableaux PHP Superglobales PHP Expression régulière PHP

Formulaires PHP

Gestion des formulaires PHP Validation de formulaire PHP Formulaire PHP requis URL/courriel du formulaire PHP Formulaire PHP terminé

PHP Avancé

Date et heure PHP Inclure PHP Gestion des fichiers PHP Fichier PHP Ouvrir/Lire Création/écriture de fichier PHP Téléchargement de fichier PHP Cookies PHP Séances PHP Filtres PHP Filtres PHP avancés Fonctions de rappel PHP PHPJSON Exception PHP

POO PHP

PHP Qu'est-ce que la POO Classes/Objets PHP Constructeur PHP Destructeur PHP Modificateurs d'accès PHP Héritage PHP Constantes PHP Classes abstraites PHP Interface PHP Caractéristiques PHP Méthodes statiques PHP Propriétés statiques PHP Espaces de noms PHP Itérables PHP

Base de données MySQL

Base de données MySQL Connexion MySQL Créer une base de données MySQL Créer une table MySQL MySQL Insérer des données MySQL obtenir le dernier ID MySQL Insérer plusieurs MySQL préparé MySQL Sélectionner les données MySQL Où Trier MySQL par MySQL Supprimer les données Données de mise à jour MySQL Données de limite MySQL

XML PHP

Analyseurs PHP XML Analyseur PHP SimpleXML PHP SimpleXML - Obtenir Expatriation PHP XML PHP XML DOM

PHP -AJAX

Introduction à AJAX PHP AJAX Base de données AJAX XML AJAX Recherche en direct AJAX Sondage AJAX

Exemples PHP

Exemples PHP Compilateur PHP Questionnaire PHP Exercices PHP Certificat PHP

Référence PHP

Présentation de PHP Tableau PHP Calendrier PHP Date PHP Annuaire PHP Erreur PHP Exception PHP Système de fichiers PHP Filtre PHP FTP PHP PHPJSON Mots clés PHP PHP LibxmlComment Messagerie PHP Mathématiques PHP Divers PHP PHP MySQL Réseau PHP Contrôle de sortie PHP Expression régulière PHP PHP SimpleXML Flux PHP Chaîne PHP Gestion des variables PHP Analyseur PHP XML Code postal PHP Fuseaux horaires PHP

Fonction PHP mysqli real_connect()

❮ Référence PHP MySQLi

Exemple - Style orienté objet

Ouvrez une nouvelle connexion au serveur MySQL, avec des options de connexion supplémentaires :

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

Regardez l'exemple de style procédural en bas.


Définition et utilisation

La fonction real_connect() / mysqli_real_connect() ouvre une nouvelle connexion au serveur MySQL.

Cette fonction diffère de connect() des manières suivantes :

  • real_connect() nécessite un objet valide créé par init()
  • real_connect() peut être utilisé avec options() pour définir différentes options pour la connexion
  • real_connect() a un paramètre flag

Syntaxe

Style orienté objet :

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

Style procédural :

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

Valeurs des paramètres

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

Détails techniques

Valeur de retour : VRAI en cas de succès. FAUX en cas d'échec
Version PHP : 5+
Journal des modifications PHP : PHP 5.6 : indicateur MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT ajouté

Exemple - Style procédural

Ouvrez une nouvelle connexion au serveur MySQL, avec des options de connexion supplémentaires :

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


❮ Référence PHP MySQLi