Jump to content

Drop all table where


madcrazy1

Recommended Posts


    $username="root";
    $password="mypassword";
    $database="mydatabase";
    mysql_connect('localhost',$username,$password);
    mysql_select_db($database) or die( "Unable to select database");
    
    function drop_empty_tables(){
        $tables = mysql_query('SHOW TABLES');
        while($table = mysql_fetch_array($tables)){
            $table = $table[0];
            $records = mysql_query("SELECT * FROM $table");
            if(mysql_num_rows($records) == 0){
                mysql_query("DROP TABLE $table");
                echo "DROP TABLE $table;\n";
            }
        }
    }
    
    drop_empty_tables();


 

any table on the server the user has rights to with 0 row count will be droped

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.