Deleting multiple tables with a common prefix

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
//Connect to the database server and select our database
$link = mysql_connect('rdbms.strato.de', 'UXXXX', 'epsilon eridani') 
	or die('Could not connect: ' . mysql_error());
mysql_select_db('DBXXXX') or die('Could not select database');
 
//get table list
$result = mysql_query("SHOW TABLES") or die(mysql_error());
 
//kill tables
$tokillprefix = "jos_";
while($row=mysql_fetch_array($result)){
 	if(substr($row[0],0,strlen($tokillprefix)) == $tokillprefix){
	 	echo "killing $row[0] <br>\n";
		mysql_query("DROP TABLE $row[0]") or die(mysql_error());
	}
}
 
?>done
This entry was posted in Computers and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>