简体   繁体   中英

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.

What's not working

The code returns an empty page.

What I tried to do

  • I added 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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