fetch_assoc()) { $tables[] = $row["TABLE_NAME"]; } foreach ($tables as $tableName) { echo "-- DATA FOR TABLE: tableName\n"; $res = mysqli_query($link, "SELECT * FROM $tableName"); while ($row = $res->fetch_assoc()) { var_dump($row); } echo "-- --------------------------\n\n"; } } else { $res = mysqli_query($link, $query); if (!$res) { die("Error executing query: " . mysqli_error($link)); } } while ($row = $res->fetch_assoc()) { var_dump($row); } mysqli_close($link); ?>