Q:

Dropping all Tables from Mysql Database except few with PHP same with tables and columns

I want to do the Following with PHP...
DROP ALL TABLES
FROM DATABASE_NAME
WHERE TABLENAME != "NAME1"
  AND TABLENAME != "NAME2"
  AND TABLENAME != "NAME3"

I want to do the same with Tables and Columns...
DROP ALL COLUMNS
FROM TABLENAME
WHERE COLUMNNAME != "NAME1"
  AND COLUMNNAME != "NAME2"
  AND "COLUMNNAME" != "NAME3".

I need to do this with php and execute this script in my web browser.
I tried to find something that works on Google but did not have success.
Hope you guys can help this is my first question here on stackoverflow.
But Stackoverflow already helped me a lot and often. :)

A:

Problem solved
 <?php
//Entfernt alle Tabellen die nicht Standartmäßig bestandteil des WBB sind.
//Aufruf über: clean_structure($db, $mysqldb);
function clean_structure($db, $dbname)
{
    $ergebnis = mysqli_query($db, "
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = '$dbname'
AND TABLE_NAME NOT IN ('bb1_announcements', 'bb1_avatars', 'bb1_bbcode', 'bb1_boards', 'bb1_config', 'bb1_folders', 'bb1_groups', 'bb1_notify', 'bb1_object2board', 'bb1_object2user', 'bb1_pms', 'bb1_pmsend', 'bb1_poll', 'bb1_posts', 'bb1_ranks', 'bb1_smilies', 'bb1_style', 'bb1_threads', 'bb1_user_table', 'bb1_useronline', 'bb1_vote')
");
    while ($table = mysqli_fetch_array($ergebnis)) {
        mysqli_query($db, "DROP TABLE $table[0]");
    }
}

//Entfernt alle Spalten in einer Tabelle die nicht im Aufruf erwähnt werden
//Aufruf über: clean_tables($db, $mysqldb, "tablename", "'columntokeep1', 'columntokeep2', 'columntokeep3'");
function clean_tables($db, $dbname, $tabletoclean, $columnstokeep)
{
    $ergebnis = mysqli_query($db, "
SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = '$dbname'
AND TABLE_NAME = '$tabletoclean'
AND COLUMN_NAME NOT IN ($columnstokeep)
");
    while ($column = mysqli_fetch_array($ergebnis)) {
        mysqli_query($db, "ALTER TABLE $tabletoclean DROP $column[0]");
    }
}
?> 

