MySQLi repair and optimize tables


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.