how to clear mysql db tables on a shared server

Php, Divx, Apache, phpBB
Forum rules
Do not post any code that circumvents rules of any server. You are responsible for anything you use here.
Post Reply
darknkreepy3#
Site Admin
Posts: 247
Joined: Tue Oct 27, 2009 9:33 pm

how to clear mysql db tables on a shared server

Post by darknkreepy3# »

If your server is a shared server, you might have access to a mysql control panel, or you might not. Most of the time you don't have Administrative privileges, so there are some problems that can arise with scripted CMS programs like phpBB3. I ran into a problem where I erased and copied the entire phpBB3 folder, and when I initialized the software in the install steps, I would get a white window that seemed to stand for a crashed phpBB3 install. So, what I did was write a program that would wildcard all tables in the phpBB database.

I knew my user name and password I created. I also knew the db server name, which is not the same as the website. In this circumstance the shared server only allowed 'localhost' to be the db server in my scripts unlike iPower which allows remote connection via an external server name. So, I wrote a script to allow login with PHP, and then asked php all of the tables names, and erased them one at a time. Then I reinstalled phpBB3 and everything worked fine.

Here is the script

Code: Select all

<?php
//phpbb3 clean tool v1.0 by Kristoffe Brodeur.  All Rights Reserved.
$server="localhost";
$user="enter-user-name-here";
$pass="enter-password-here";
//this was the name of the faulty tables creating a bug, yours may be different
$table="phpbb_";
//some shared servers give you a db name, most allow you to create one in a mysql control panel
$db="enter-db-name-here";
//-----
$link=mysql_connect($server,$user,$pass);
echo "$server<br />$user<br />$pass<hr />";
//
if(!$link)
  {
  die('cannot connect to database server, sorry:<br /><b>'.mysql_error()."</b>");
  }
mysql_select_db($db,$link);
$numTables=mysql_list_tables($db);
//
while($row=mysql_fetch_row($numTables))
	{
	$delete_table=mysql_query("DROP TABLE IF EXISTS $row[0]");
	//
	if($delete_table)
		{
		echo "$row[0] removed <br />";
		}
	else
		{
		echo "$row[0] still present!<br />";
		}
	}
mysql_free_result($numTables);
mysql_close($link);
?>
Post Reply