未使用PHP显示Mysql主机信息
我正在学习php/mysql教程。示例脚本将我连接到mysql数据库,但没有显示它应该做什么 有问题的路线是未使用PHP显示Mysql主机信息,php,mysql,database-connection,Php,Mysql,Database Connection,我正在学习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("C
("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());
}
?>
我只是在屏幕上看到了“Hostname:”。您需要在
mysqli\u get\u host\u info()
函数中指定您的mysqli对象。请尝试以下代码:
<?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();
?>