我试图在我的网站上显示数据库中的表列表,但我找不到一种方法可以在实际页面上显示SHOW tables
的输出。这是我的代码:
<?php
$servername = "localhost";
$username = "***";
$password = "***";
$dbname = "***";
//Create Connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
//Check Connection
if (!$conn) {
die("Connection failed: " .mysqli_connect_error());
}
$sql = "SHOW tables";
$result = mysqli_query($conn, $sql);
while ($row = mysqli_num_rows($result)) {
echo $row[];
}
mysqli_close($conn);
?>
答案 0 :(得分:0)
应该是,
while($table = mysqli_fetch_array($result)) {
echo($table[0] . "<BR>");
}