mysqli::$host_info
(mysqli_get_host_info) Returns a string representing the connection type used
Function name: mysqli::$host_info()
Applicable version: PHP 5, PHP 7
Function description: the mysqli::$host_info() method is used to obtain the MySQL host information of the currently connected.
usage:
$mysqli = new mysqli("localhost", "username", "password", "database"); // 检查连接是否成功if ($mysqli->connect_errno) { echo "连接失败: " . $mysqli->connect_error; exit(); } // 获取MySQL主机信息$hostInfo = $mysqli->host_info; // 输出MySQL主机信息echo "连接到的MySQL主机信息:" . $hostInfo; // 关闭数据库连接$mysqli->close();
Example explanation:
new mysqli()
function to create a MySQL database connection object.$mysqli->connect_errno
property. If the connection fails, we use the $mysqli->connect_error
attribute to output the connection error message and exit the script.$mysqli->host_info
attribute to get the MySQL host information of the currently connected.echo
statement to output MySQL host information.$mysqli->close()
method to close the database connection.Notes:
mysqli::$host_info()
method, you must first create a valid MySQL connection object.$mysqli->host_info
attribute returns an empty string.