<?php
// set time limit to 0 so it will not timeout.
set_time_limit(0);
// connect to the mysql server
mysql_connect("localhost", "root", "") or die("Could not connect: " . mysql_error());
//select any one of the db - testdb is always safe.
mysql_select_db("test");
// html log to see colored logs
$filename = date("Y-m-d H-i-s A").'.html';
$handle = fopen($filename,"w+");
// specify the wild card for the dbs you want to check for temp tables.
$result = mysql_query("show databases like 'user_%'");
// loop through the database returned by the above query.
while ($row = mysql_fetch_array($result)) {
$to_log= "<h3>Connecting to database: ".$row[0]."</h3>";
echo $to_log;
fwrite($handle,$to_log);
mysql_select_db( $row[0]);
// here you can specify the different wildcards for the temp tables
$temp_arr=array("temp_","temp2_");
$loop_count=0;
foreach( $temp_arr as $key)
{
$table_query="show tables like '".$key."%'";
$to_log=$table_query."<br>";
echo $to_log;
fwrite($handle, $to_log);
$result1 = mysql_query($table_query);
while ($row1 = mysql_fetch_array($result1)) {
if($loop_count%2==0)
$color="#0000FF";
else
$color="#339933";
$query="drop table ".$row[0].".".$row1[0];
if(mysql_query($query))
$result_="OK";
else
$result_="<font color=red>".mysql_error()."</font>";
$to_log= "<i><font color=$color>".$query."</font>:: $result_ <br>" ;
echo $to_log;
fwrite($handle, $to_log);
}
$loop_count++;
}
}
mysql_free_result($result);
fclose($handle);
?>