English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
A função mysqli_get_host_info() do PHP retorna uma string que descreve o tipo de conexão usada
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.
mysqli_get_host_info($con);
Número de ordem | Parâmetros e descrição |
---|---|
1 | con(opcional) Este é um objeto que representa a conexão com o MySQL Server. |
A função mysqli_get_host_info() do PHP retorna uma string que especifica o nome do host e o tipo de conexão.
This function was initially introduced in PHP version5introduced and can be used in all higher versions.
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
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
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
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