3

Im trying to echo out all table names in a specific database, but I can't find a working solution! Here is the code I have to far:

$sql = "SHOW TABLES FROM test";
$result1 = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result1);
if ($resultCheck > 0){
    while ($row = mysqli_fetch_assoc($result1)){
        echo $row;
    }
}

Any help would be great!

insertusernamehere
  • 23,204
  • 9
  • 87
  • 126
Sonder12
  • 75
  • 5

2 Answers2

2

The $row is coming as an array, so you have to fetch it as

echo $row['Tables_in_test']
Rakesh Jakhar
  • 6,380
  • 2
  • 11
  • 20
1

First of all, be sure not to ask for a database outside of what the user you are using is able to see (Therefore, make sure that the user can see other databases).

One that is figured out, this is the code

$sql = "SHOW TABLES FROM test";
$result1 = $conn->query($sql);
while ($row = mysqli_fetch_assoc($result1)){
  echo $row["Tables_in_test"];
}
Francesco
  • 429
  • 4
  • 12