PHP mysqli_get_host_info() Function
In this chapter you will learn:
- Definition for PHP mysqli_get_host_info() Function
- Syntax for PHP mysqli_get_host_info() Function
- Parameter for PHP mysqli_get_host_info() Function
- Return for PHP mysqli_get_host_info() Function
- Example - Gets the MySQL server hostname and connection type
- Example - Object orient version
Definition
The mysqli_get_host_info() function returns the MySQL server hostname and the connection type.
Syntax
Object oriented style
string $mysqli->host_info;
Procedural style
string mysqli_get_host_info ( mysqli $link )
Parameter
Parameter | Is Required | Description |
---|---|---|
connection | Required. | MySQL connection |
Return
A character string representing the server hostname and the connection type.
Example 1
The following code gets the MySQL server hostname and connection type.
<?php/* ja v a2 s .co m*/
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno($con)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
echo mysqli_get_host_info($con);
mysqli_close($con);
?>
Example 2
Object orient version
<?php/*java 2 s . c o m*/
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
print $mysqli->host_info;
$mysqli->close();
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP mysqli_get_proto_info() Function
- Syntax for PHP mysqli_get_proto_info() Function
- Parameter for PHP mysqli_get_proto_info() Function
- Return for PHP mysqli_get_proto_info() Function
- Example - Get the MySQL protocol version
- Example - Object oriented style
Home » PHP Tutorial » PHP MySQLi Functions