Current Location: Home> Function Categories> mysqli::$host_info

mysqli::$host_info

(mysqli_get_host_info) Returns a string representing the connection type used
Name:mysqli::$host_info
Category:MySQLi
Programming Language:php
One-line Description:Get the MySQL host information of the currently connected

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:

  1. First, we use the new mysqli() function to create a MySQL database connection object.
  2. Then, we confirm that the connection is successful by checking the $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.
  3. Next, we use the $mysqli->host_info attribute to get the MySQL host information of the currently connected.
  4. Finally, we use the echo statement to output MySQL host information.
  5. Finally, we use the $mysqli->close() method to close the database connection.

Notes:

  • Before using mysqli::$host_info() method, you must first create a valid MySQL connection object.
  • The host information returned by this method usually contains information such as MySQL host name, port number, and protocol version.
  • If the connection fails, the $mysqli->host_info attribute returns an empty string.
Similar Functions
Popular Articles