Btown2 Posted July 15, 2008 Share Posted July 15, 2008 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 https://forums.phpfreaks.com/topic/114752-useful-script/ Share on other sites More sharing options...
rhodesa Posted July 15, 2008 Share Posted July 15, 2008 http://www.phpmyadmin.net/ works wonders too Link to comment https://forums.phpfreaks.com/topic/114752-useful-script/#findComment-590056 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.