Sql php script to generate Drop table with prefixes mysql is helpful for drupal prefix
Yuo can be in situation for deleting many tables from database with particular prefix.I was in such a situation where
i needed to delete 200 tables from my database with prefix "vb".So i used this script for generating the drop table statement
and just copied to mysql window. and thats all.it work fine.
<?php
// This script will make DROP queries for getting rid of tables that have the same prefix
$dbname = 'dbname';//change
$dbhost = 'dbhost';//change
$dbuser = 'dbuser';//change
$dbpass = 'dbuserpas';//change
$prefix="vo"; //Define the Table prefix Which Was used
if (!mysql_connect($dbhost, $dbuser, $dbpass))
{
print 'Could not connect to mysql';exit;
}
$result = mysql_list_tables($dbname);
if (!$result)
{
print "DB Error, could not list tables\n";
print 'MySQL Error: ' . mysql_error();
exit;
}
if ($prefix == null)
{
print "<b>TABLE LIST:</b><br>";
while ($row = mysql_fetch_row($result))
{
print "Table: $row[0]<br>";
}
echo "\n No prefix";
} else
{
echo "<b>DROP TABLE QUERY FOR TABLES WITH PREFIX '".$prefix."'</b>
<br>Copy this query into your MySQL program and execute to remove these tables.<br><br>";
while ($row = mysql_fetch_row($result))
{
if (substr($row[0], 0, strlen($prefix)) == $prefix)
{
print "DROP TABLE $row[0];<br>";
}
}
}
mysql_free_result($result);
?>
- Login or register to post comments
Delicious
Digg
StumbleUpon
Facebook
Google
Yahoo
Technorati
Icerocket

Sign In





