Skip to content

Instantly share code, notes, and snippets.

@wordpressandphpdeveloper
Last active September 6, 2021 12:26
Show Gist options
  • Save wordpressandphpdeveloper/a1268ad5f0395c6fef9c to your computer and use it in GitHub Desktop.
Save wordpressandphpdeveloper/a1268ad5f0395c6fef9c to your computer and use it in GitHub Desktop.
Php script to show all tables in a MySQL schema
<?php
//open database connection
$mysqli = new mysqli(<host>,<username>,<password>,<schema>);
//Display error message
if ($mysqli->connect_error) {
die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}
$sql="SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = '<schema name>'";
$result=$mysqli->query($sql);
while ( $tables = $result->fetch_assoc())
{
echo "<br>".$tables['TABLE_NAME'];
}
// Free memory by clearing result
$result->free();
// close connection
$mysqli->close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment