You are here: Home > PHP Tutorial > Optimize All Tables In A MySQL Database

Optimize All Tables In A MySQL Database

Description

If you have a database driven site and you want to optimize MySQL tables then this is perfect. It goes through all the tables in a MySQL database and does table optimization on each one using the MySQL Optimize Table syntax.

The code


<?php

dbConnect()

$alltables = mysql_query("SHOW TABLES");

while ($table = mysql_fetch_assoc($alltables))

{

   foreach ($table as $db => $tablename)

   {

       mysql_query("OPTIMIZE TABLE '".$tablename."'")

           or die(mysql_error());

   }

   

}

?>

Reference - http://www.totallyphp.co.uk

Tags: , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

Leave a Reply


three + = 5