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());
}
?>
我刚在屏幕上看到 "Hostname: "。
您需要在 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();
?>
我正在学习 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());
}
?>
我刚在屏幕上看到 "Hostname: "。
您需要在 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();
?>