English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The mysqli_get_host_info() function returns a string describing the connection type used
mysqli_get_host_info()The function is used to obtain information about the host, that is, the connection type used and the name of the host server.
mysqli_get_host_info($con);
Serial number | Parameters and descriptions |
---|---|
1 | con (optional) This is an object representing the connection to the MySQL Server. |
The PHP mysqli_get_host_info() function returns a string specifying the host name and connection type.
This function was originally introduced in PHP version5introduced and can be used in all higher versions.
The following example demonstratesmysqli_get_host_info()Function usage (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 object-oriented style, the syntax of this function is$con-> host_info. The following 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
The following 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 "Cannot connect to MySQL: " . mysqli_connect_error(); } echo mysqli_get_host_info($connection_mysql); mysqli_close($connection_mysql); ?>
Output result
localhost via TCP/IP