How to repair tables with a php file

I just run recently on a problem that was affecting a forum that I administer. One of the forum’s table was marked as crashed and therefor the whole site wasn’t working. Since I’m not the root admin, I do not have complete access at the site’s resources. If I’d had mysql access, this could have been fixed easily. But I didn’t have. And I couldn’t wait for the root admin to come on-line, I had to do something. Fortunately, I did had ftp access so I made a php file that could fix that table for me. Here is the code:

<?php
$db_server = ‘localhost’;
$db_name = ‘ ‘;
$db_user = ‘ ‘;
$db_passwd = ‘ ‘;
function secure($input)
{
$badchars = array(”<”, “>”, “/”, “‘”, “\”", “;”,”*”, “FROM”,”SELECT”,” “);
$input = str_replace($badchars, “”, $input);
return $input;
}
if($_POST)
{
$db_table=$_POST[’table’];
$db_table=secure($db_table);
$conexiune=mysql_connect($db_server,$db_user,$db_passwd) or die(”Erorr!”);
@mysql_select_db($db_name) or die(”Erorr2!”);
mysql_query(”REPAIR TABLE $db_table”);
echo “Done!”;
}
else
{
echo “<form method=’POST’ action=’repair.php’>”;
echo “Insert here the table’s name : <input type=’text’ name=’table’ value=”>”;
echo “<br><input type=’submit’ name=’submit’ value=’Repair’></form>”;
}
?>

All you have to do is to upload that file somewhere in the root and run it. Then, type in the table marked as crashed’s name and press repair. That’s it! It worked for me!

Tags: , , ,
permalinkRead More CommentComments (0) CatPhp tricks

Leave a Reply

CSS Template by RamblingSoul | Tomodachi theme by Theme Lab
Anime