PHP mysqli $host_info Property
The PHP mysqli::$host_info / mysqli_get_host_info() function returns a string describing the connection represented by the mysql parameter (including the server host name).
Syntax
//Object-oriented style $mysqli->host_info; //Procedural style mysqli_get_host_info(mysql)
Parameters
mysql |
Required. For procedural style only: Specify a mysqli object returned by mysqli_connect() or mysqli_init(). |
Return Value
Returns a character string representing the server hostname and the connection type.
Example: Object-oriented style
The example below shows the usage of mysqli::$host_info property.
<?php //establishing connection to the database $mysqli = new mysqli("localhost", "user", "password", "database"); if ($mysqli->connect_errno) { echo "Connection error: ". $mysqli->connect_error; exit(); } //printing the host information printf("Host info: %s\n", $mysqli->host_info); //closing the connection $mysqli->close(); ?>
The output of the above code will be similar to:
Host info: Localhost via UNIX socket
Example: Procedural style
The example below shows the usage of mysqli_get_host_info() function.
<?php //establishing connection to the database $mysqli = mysqli_connect("localhost", "user", "password", "database"); if (mysqli_connect_errno()) { echo "Connection error: ". mysqli_connect_error(); exit(); } //printing the host information printf("Host info: %s\n", mysqli_get_host_info($mysqli)); //closing the connection mysqli_close($mysqli); ?>
The output of the above code will be similar to:
Host info: Localhost via UNIX socket
❮ PHP MySQLi Reference