Posted By

ginoplusio on 01/25/10


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite


Run REPAIR and OPTIMIZE on every table of your MYSQL DB

 / Published in: PHP


  1. function fixTables($dbname) {
  2. // search for all the tables of
  3. // a db and run repair and optimize
  4. // note: this can take a lot of time
  5. // if you have big/many tables.
  6. $result = mysql_list_tables($dbname) or die(mysql_error());
  7. while ($row = mysql_fetch_row($result)) {
  8. mysql_query("REPAIR TABLE $row[0]");
  9. mysql_query("OPTIMIZE TABLE $row[0]");
  10. }
  11. }

Report this snippet  


RSS Icon Subscribe to comments
Posted By: AboutPhps on September 14, 2014

I'm new to php. Setup question: Where do you put this script to run.

You need to login to post a comment.