在MySQL中查询数据库中的所有表;PHP


Query all Tables in Database in MySQL & PHP

如何制作表列表并在php中遍历它们?

我试图弄清楚mysqli_query将如何输出,但一直出现错误。

$link = mysqli_connect($host,$user,$pass);
mysqli_select_db($link,$name);
$result = mysqli_query($link, "SHOW TABLES");
echo $result; 

从本质上讲,我希望能够将它们放在一个数组中,遍历数组中的每个表,并对它们进行快速查询。

谢谢你的帮助。

编辑:标题

请注意,$result不是字符串,而是MySQLi结果。

使用类似的东西

while ($row = $result->fetch_assoc()) {
    /* Process $row here ... */
    var_dump($row);
}

这应该能在中工作

$tables = array();
$result = mysqli_query($link, "SHOW TABLES");
while (($row = mysqli_fetch_assoc($result)) !== null)
{
        $tables[] = $row[key($row)];
}