在网站上显示MySQL SHOW表的结果

时间:2016-01-22 05:23:09

标签: mysql mysqli php-5.4

我试图在我的网站上显示数据库中的表列表,但我找不到一种方法可以在实际页面上显示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);

?>

1 个答案:

答案 0 :(得分:0)

应该是,

while($table = mysqli_fetch_array($result)) { 
    echo($table[0] . "<BR>");  
}