Tag Archives: database

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
Posted in Computers | Tagged , , | Leave a comment