You are on page 1of 2

<?php /* Template Name: Optimize Table */ ?> <?php get_header(); ?> <?

php // Statement to select the databases $db_select = 'SHOW DATABASES'; // Query mySQL for the results $db_result = MYSQL_QUERY($db_select); // Loop through all the databases WHILE ($db_row = MYSQL_FETCH_ARRAY($db_result)) { // Select currently looped database and continue only if successful IF (MYSQL_SELECT_DB($db_row[0])) { // Echo database name ECHO "<br><b>"; ECHO $db_row[0]; ECHO "</b><br>"; // Statement to select the tables in the currently looped databas e $tbl_status = 'SHOW TABLE STATUS FROM ' . $db_row[0]; // Query mySQL for the results $tbl_result = MYSQL_QUERY($tbl_status); // Check to see if any tables exist within database IF(MYSQL_NUM_ROWS($tbl_result)) { // Loop through all the tables WHILE ($tbl_row = MYSQL_FETCH_ARRAY($tbl_result)) { // Statement to optimize table $opt_table = 'OPTIMIZE TABLE ' . $tbl_row[0]; // Query mySQL to optimize currently looped table $opt_result = MYSQL_QUERY($opt_table); // Echo table name ECHO " <i>"; ECHO $tbl_row[0]; ECHO "</i><br>"; } // End table while loop } ELSE { // Alert that there are no tables within database ECHO " <i>No Tables</i><br>"; } // End table exists if statement } // End database if statement } // End database while loop

// Alert that operation was successful ECHO "<br><br><b>Above tables successfully optimized.</b>"; ?> <?php get_footer(); ?>

You might also like