Skip to content

Instantly share code, notes, and snippets.

@hussnainsheikh
Created September 21, 2017 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hussnainsheikh/289c3ce74eaa366ef2f83f6b0e21a7a7 to your computer and use it in GitHub Desktop.
Save hussnainsheikh/289c3ce74eaa366ef2f83f6b0e21a7a7 to your computer and use it in GitHub Desktop.
This is simple PHP script which shows all the tables of a database. You just need to provide database details. It can be helpful if we just have database details and do not know about the database tables.
<?php
$db = 'database'; //Database name
$host = 'host'; //Hostname or Server ip
$user = 'database_user'; //Database user
$pass = 'password'; //Database user password
$con = mysql_connect($host,$user,$pass);
if($con){
$link = mysql_select_db($db) or die("no database").mysql_error();
$count = 0;
if($link){
$sql = "SHOW TABLES FROM `$db`";
$result = mysql_query( $sql, $con);
if(mysql_query($sql,$con)){
echo $sql."<br> <br>";
while ($row = mysql_fetch_row($result)) {
echo "Table ".++$count.": {$row[0]}<br>";
$table_name = $row[0];
}
echo "<br>Total No. of Tables: " . $count;
}
else{
echo "Error in query.";
}
}
else{
echo "Database not found.";
}
}
else{
echo "Connection Failed.";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment