Last active
September 6, 2021 12:26
-
-
Save wordpressandphpdeveloper/a1268ad5f0395c6fef9c to your computer and use it in GitHub Desktop.
Php script to show all tables in a MySQL schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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