Posted By

ginoplusio on 02/01/10


Tagged

mysql php table mysqli optimize repair


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

ginoplusio


MySQLi repair and optimize tables


 / Published in: PHP
 

URL: http://www.barattalo.it/2010/01/29/10-php-usefull-functions-for-mysqli-improved-stuff/

  1. function fixTables($conn,$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. global $conn;
  7. if ( $rs = $conn->query("SHOW TABLES FROM $dbname") ) {
  8. while ( $r = $rs->fetch_array() ) {
  9. $conn->query("REPAIR TABLE {$r[0]}");
  10. $conn->query("OPTIMIZE TABLE {$r[0]}");
  11. }
  12. $rs->free();
  13. }
  14. }

Report this snippet  

You need to login to post a comment.