Skip to content

Instantly share code, notes, and snippets.

@kruxor
Created April 15, 2014 00:44
Show Gist options
  • Save kruxor/10692962 to your computer and use it in GitHub Desktop.
Save kruxor/10692962 to your computer and use it in GitHub Desktop.
show all tables in the selected database
<?php
/* list db structure */
function show_all_db() {
global $db;
global $db_name;
$out = "";
$sql = "SELECT table_name, column_name
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_schema = '$db_name'
ORDER BY table_name, ordinal_position";
$result = $db->query($sql);
if(!$result) { return "Missing Main Table: $db_name "; }
while($row = mysqli_fetch_assoc($result)) {
$table_name = $row['table_name'];
$column_name = $row['column_name'];
$out .= "$table_name : $column_name<br/>";
}
return $out;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment