简体   繁体   English

打印数据库中的所有表

[英]Printing all tables in a database

My code 我的密码

<?php
$connessione = mysqli_connect("localhost","root","","my_db");
$query = mysqli_query($connessione,"SHOW TABLES");
$array=mysqli_fetch_array($query);
print_r($array,1);
?>

What it should do 它应该做什么

Printing all tables in my_db. 打印my_db中的所有表。

What's not working 什么不起作用

The code returns an empty page. 该代码返回一个空白页。

What I tried to do 我试图做的

  • I added error_reporting(E_ALL); 我添加了error_reporting(E_ALL); at the top of the page, but it doesn't return nothing; 在页面顶部,但不会返回任何内容;
  • I run the query SHOW TABLES using phpMyAdmin and it works as it should. 我使用phpMyAdmin运行查询SHOW TABLES ,它可以正常工作。

My question 我的问题

How can I fix my code? 如何修复我的代码?

Here's what you need to do: 这是您需要做的:

<?php
    $connessione = mysqli_connect("localhost","root","","my_db");
    $query = mysqli_query($connessione,"SHOW TABLES");
    while($row = mysqli_fetch_array($query)){
        print_r($row);
   }
?>

See here for a description of what mysqli_fetch_array actually does. 有关mysqli_fetch_array实际作用的说明,请参见此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM