English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Tutorial básico PHP

Tutorial avançado PHP

PHP & MySQL

Manual de referência PHP

Uso e exemplo da função mysqli_get_host_info() do PHP

PHP MySQLi Reference Manual

A função mysqli_get_host_info() do PHP retorna uma string que descreve o tipo de conexão usada

Definição e uso

mysqli_get_host_info()A função é usada para obter informações sobre o host, ou seja, o tipo de conexão usado e o nome do servidor do host.

Sintaxe

mysqli_get_host_info($con);

Parâmetro

Número de ordemParâmetros e descrição
1

con(opcional)

Este é um objeto que representa a conexão com o MySQL Server.

Retorno

A função mysqli_get_host_info() do PHP retorna uma string que especifica o nome do host e o tipo de conexão.

PHP version

This function was initially introduced in PHP version5introduced and can be used in all higher versions.

Online example

The following examples demonstratemysqli_get_host_info()Usage of the function (procedural style)-

<?php
  //Establish connection
   $con = mysqli_connect("localhost", "root", "password", "mydb");
   //Host information
   $info = mysqli_get_host_info($con);
   print("Host information: " . $info);
   //Close connection
   mysqli_close($con);
?>

Output result

Host information: localhost via TCP/IP

Online example

In the object-oriented style, the syntax of this function is$con-> host_info. Below is an example of this function in object-oriented style-

<?php
   //Establish connection
   $con = new mysqli("localhost", "root", "password", "mydb");
   //Host information
   $info = $con-> host_info;
   print("Host information: " . $info);
   //Close connection
   $con -> close();
?>

Output result

Host information: localhost via TCP/IP

Online example

Below ismysqli_get_host_infoAnother example of the function-

<?php
   //Establish connection
   $con = mysqli_connect("localhost", "root", "password", "mydb");
   $code = mysqli_connect_errno();
   if ($code) {
      print("Connection failed: " . $code);
   } else {
      print("Connection established successfully" . "\n");
      $info = mysqli_get_host_info($con);
      print("Host information: " . $info);
   }
?>

Output result

Host information: localhost via TCP/IP

Online example

Return the MySQL server hostname and connection type:

<?php
   $connection_mysql = mysqli_connect("localhost","root","password","mydb");
   
   if (mysqli_connect_errno($connection_mysql)){
      echo "Unable to connect to MySQL: " . mysqli_connect_error();
   }
   echo mysqli_get_host_info($connection_mysql);   
   mysqli_close($connection_mysql);
?>

Output result

localhost via TCP/IP

PHP MySQLi Reference Manual