0

I had a basic system that has an input for inserting dynamic tables in the database and when the table is created, I want to show the list of table name on dropdown list. And I want to select the table name and insert a file on it.

The file is csv, the problem is how do I display all the data from all the tables I had created in the database on my system.

This is what I want to do:

SELECT ALL FROM (ALL TABLES IN THE DATABASE) - - example only 

Then query the result.

I prefer php and sql for doing this.

Is it possible?

2 Answers2

0

Hi You can use below query to find all tables in specific database.

show tables from DBNAME;

0

Try this:

<?php
$databaseName = '<database name>';

$pdo = new Pdo('mysql:host=<host>;dbname=' . $databaseName, '<user>', '<password>');

$result = $pdo->query('SHOW TABLES FROM ' . $databaseName)->fetchAll(PDO::FETCH_NUM);

$tables = [];
foreach ($result as $r) {
    $tables[] = $r[0];
}

$data = [];
foreach ($tables as $table) {
    $data[$table] = $pdo->query('SELECT * FROM ' . $table)->fetchAll(PDO::FETCH_ASSOC);
}

var_dump($tables);
var_dump($data);
Waldson Patricio
  • 1,489
  • 13
  • 17