<?php
//OPTIMIZE the whole database
$sql = 'OPTIMIZE TABLE ';
$res = mysql_list_tables($mysql->DB_NAME); 
$nt = mysql_num_rows($res);
for($a=0; $a<$nt; $a++)
{ 
$row = mysql_fetch_row($res);
$table = $row[0];
$sql .= '`'.$row[0].'`, ';
}
$sql = substr($sql, 0, -2).';';
$mysql->do_query($sql);
?>