Mysql主机信息未显示使用PHP


Mysql Host information not showing using PHP

我正在学习php/mysql教程。将我连接到mysql数据库的示例脚本没有显示它应该显示的内容。

有问题的线路是

("Host information: %'n", mysqli_get_host_info($mysqli));

还有的其余代码

 <?php
$mysqli=new mysqli("localhost", "root", "Im not pasting this", "or this");
if (mysqli_connect_errno()){
    printf("Connect failed: %s'n", mysqli_connect_error());
    exit();
    } else {
        printf("Host information: %'n", mysqli_get_host_info());
}
?>

我只是在屏幕上看到"主机名:"。

您需要在mysqli_get_host_info()函数中指定您的mysqli对象-http://php.net/manual/en/mysqli.get-host-info.php.试试这个代码:

     <?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s'n", mysqli_connect_error());
    exit();
}
/* print host information */
printf("Host info: %s'n", $mysqli->host_info);
/* close connection */
$mysqli->close();
?>