<?
//---------------------------------------------------------
//---- Optimize & Repair Database from Tracker by D3SI
//---------------------------------------------------------
require "include/bittorrent.php";
dbconn(false);
loggedinorreturn();
if (get_user_class() < UC_SYSOP)
stderr("Error", "Zugriff verweigert.");
$tables = "";
$tablesshow = mysql_query("SHOW TABLES FROM `".$mysql_db."`");
while (list($table) = mysql_fetch_row($tablesshow)){
$tables .= "`".mysql_real_escape_string($table)."`,";
}
$tables .= "...";
$tables = str_replace(",...", "", $tables);
mysql_query("OPTIMIZE TABLE ".$tables);
//mysql_query("REPAIR TABLE ".$tables);

stderr("Datenbank", "Datenbank Optimiert & Repariert!");
//---------------------------------------------
//---- END
//---------------------------------------------
?>
<?php
require_once("include/secrets.php");
$db = mysql_connect($mysql_host, $mysql_user, $mysql_pass);
$sql = "SHOW DATABASES";
$dbs_result = mysql_query($sql, $db); 
if(mysql_num_rows($dbs_result)) 
{ 
while($dbs_row=mysql_fetch_assoc($dbs_result))
{
$database = $dbs_row["Database"]; 
mysql_select_db($database, $db);
$sql = "SHOW TABLE STATUS"; 
$tbls_result = mysql_query($sql, $db);
if(mysql_num_rows($tbls_result)) 
{
while($tbls_row=mysql_fetch_assoc($tbls_result)) 
{
$TableName = "`".$tbls_row["Name"]."`";
$sql = "REPAIR TABLE ".$TableName; 

mysql_query($sql, $db);
$sql = "OPTIMIZE TABLE ".$TableName;

mysql_query($sql, $db);
}
}
}
}

mysql_close($db);
header("Refresh: 0; url=mysql_overview.php");
?> 