Created
September 21, 2017 15:03
-
-
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.
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 | |
$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