Skip to content

Instantly share code, notes, and snippets.

@hussnainsheikh
Created December 19, 2017 12:47
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/9a6cfe809217708fa2b06bccdef480cd to your computer and use it in GitHub Desktop.
Save hussnainsheikh/9a6cfe809217708fa2b06bccdef480cd to your computer and use it in GitHub Desktop.
Simplet php script to show all DATABASES which are created on a host. Enjoy!
<?php
$host = 'HOST'; //Hostname or Server ip
$user = 'USER'; //Database user
$pass = 'PASS'; //Database user password
$con = mysql_connect($host,$user,$pass);
if($con){
$count = 0;
$sql = "SHOW DATABASES";
$result = mysql_query( $sql, $con);
if(mysql_query($sql,$con)){
echo $sql."<br> <br>";
while ($row = mysql_fetch_row($result)) {
echo "DATABASE ".++$count.": {$row[0]}<br>";
$table_name = $row[0];
}
echo "<br>Total No. of DATABASES: " . $count;
}
else{
echo "Error in query.";
}
}
else{
echo "Connection Failed.";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment