Jump to content

useful script


Btown2

Recommended Posts

A lot of times i see people asking for an easy way to remove tables from their databases. So here I submit this simple script that gets all of the tables in a DB, lists them with a checkbox, and remove the checked ones. It is very useful for dropping a lot of tables without worry of dropping ones you still need (ie phpbb2 stuff and the like). So give it a try, tell me what you think and enjoy.

 

ps. I set it up to target dbcleaner.php in the form so either name the file dbcleaner.php or change it accordingly.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DB cleaner</title>
</head>

<body>
<?php
$dbname = "";
$dbpass = "";
$server = "";
$username = "";

mysql_connect($server,$username,$dbpass) or die(mysql_error());

mysql_select_db($dbname) or die(mysql_error());

if(isset($_POST['submit']))
{
	$selected_tables = $_POST['verify'];
	foreach($selected_tables as $table_to_delete)
	{
		$query = "DROP TABLE ".$table_to_delete;
		mysql_query($query) or die(mysql_error());
		echo $table_to_delete." has been deleted.<br>";
	}
	echo "<a href='dbcleaner.php'>More cleanup?</a>";
}	

else{
$query = "SHOW TABLES";
$result = mysql_query($query) or die(mysql_error());

$num_rows = mysql_num_rows($result);

echo "<center><table border='1'><th>".$num_rows." tables found.</th><th>Remove from database?</th>";

echo "<form action='dbcleaner.php' method=post>";

$i = 0;

for(;$i < $num_rows; $i++)
	{
		$table = mysql_fetch_array($result);
		echo "<tr><td>".$table[0]."</td><td><input type=checkbox name='verify[]' value='".$table[0]."'></td></tr>";
	}

echo "</table>";
echo "<br><input type=submit value='Clean the DB' name='submit'>";
}
?>	
<p>© Written by Brayton Thompson with free use for all</p>
</center>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.