Version: 1.0.1
Type: Full Script
Category: Databases
License: GNU General Public License
Description: This script checks for errors in your database tables and then repairs them when they are found.
It performs a check on all the tables then if it finds an error the script attempts to repair it. If the repair fails it tries to repair it with a better repair method that takes longer and may result in extra rows appearing in your table. If that repair fails then it uses its last resort and tries to rebuild the table. After it is done Checking and Repairing the table it will Optimize the table.
The script documents every step that is taken and then display the check and repair log on the screen.
This script only requires you to configure 5 things.
{rtf1macansicpg10000cocoartf102 {fonttblf0fswissfcharset77 Helvetica;} {colortbl;red255green255blue255;} margl1440margr1440vieww9000viewh9000viewkind0 pardtx720tx1440tx2160tx2880tx3600tx4320tx5040tx5760tx6480tx7200tx7920tx8640qlqnatural f0fs24 cf0 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Check and Repair</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php echo "Table check and repair started.<br><br>"; /** CONFIG CHANGE HERE **/ /*************************************** *************************/ /** Database Name **/ $db = "DB Name"; /** Host Address **/ $host = "Address"; /** User Name **/ $user = "User Name"; /** Password **/ $password = "Password"; /*************************************** *************************/ /** Put table name in the quotes. **/ table_check_repair("Table Name", $db, $host, $user, $password); /** Duplicate above row for all tables. **/ /** END CONFIG **/ function table_check_repair($dbname, $db, $host, $user, $password) { $conection = mysql_connect ($host, $user, $password); mysql_select_db($db); echo "The table "$dbname" was checked.<br>"; $check = "CHECK TABLE `$dbname` EXTENDED"; $results = mysql_db_query($db, $check, $conection); $results = mysql_fetch_array ($results); echo "Results: $results[Table] -> $results[Msg_text]<br>"; if ($results['Msg_text'] != "OK") { echo "The table "$dbname" did not check out well. A repair was attempted.<br>"; $repair1 = "REPAIR TABLE `$dbname` QUICK"; $results = mysql_db_query($db, $repair1, $conection); $results = mysql_fetch_array ($results); echo "Results: $results[Table] -> $results[Msg_text]<br>"; if ($results['Msg_text'] != "OK") { echo "The table "$dbname" was not fixed. A different repair was attempted.<br>"; $repair2 = "REPAIR TABLE `$dbname` EXTENDED"; $results = mysql_db_query($db, $repair2, $conection); $results = mysql_fetch_array ($results); echo "Results: $results[Table] -> $results[Msg_text]<br>"; if ($results['Msg_text'] != "OK") { echo "The table "$dbname" was not fixed. The last repair was attempted.<br>"; $repair3 = "REPAIR TABLE `$dbname` USE_FRM"; $results = mysql_db_query($db, $repair3, $conection); $results = mysql_fetch_array ($results); echo "Results: $results[Table] -> $results[Msg_text]<br>"; } } } $optimize = "OPTIMIZE TABLE `$dbname`"; $results = mysql_db_query($db, $optimize, $conection); $results = mysql_fetch_array ($results); echo "The table "$dbname" was optimized.<br>"; echo "Results: $results[Table] -> $results[Msg_text].<br><br>"; } echo "<br>The table check and repair has ended. Reload this page to test if the repairs worked."; ?> </body> </html> </body> </html>}