PHP code to get list of all mysql databases on a shared server
Posted On at by milanScript to get mysql database names on a shared hosting server.
$path="/var/lib/mysql";
$dary=array();
$dary=scandir($path);
$fh=fopen('dbList.txt','w') or die("can't open file");
$num=count($dary);
$i=0;
while($i<$num)
{
$Dposs=strpos($dary[$i],".");
if($Dposs===false)
{
$Uposs=strpos($dary[$i],"_");
if($Uposs===false)
{
//do nothing :-)
}
else
{
$var=$dary[$i]."\n";
fwrite($fh,$var);
}
}
$i++;
}
fclose($fh);
echo "done";
?>
put this script to /root folder of shared server in a folder lets say with file name scri.php. Through shell go to folder and execute as usr/bin/php -q scri.php usr/bin/php shows the installation folder of php. This script will make a file 'dbList.txt' imidiately in the same folder in which script exists. Download this file and this will be list of all mysql dbs on a shared server. DBs from the all acounts.