Method 1:
Copy codeThe Code is as follows:
<? Php
Mysql_connect ('','','');
Mysql_select_db ('');
$ Rs = mysql_query ('show tables ');
While ($ arr = mysql_fetch_array ($ rs )){
$ TF = strpos ($ arr [0], 'class _');
If ($ TF = 0 ){
$ FT = mysql_query ("drop table $ arr [0]");
If ($ FT ){
Echo "$ arr [0] deleted successfully! <Br> ";
}
}
}
?>
Method 2:
I re-installed the site today. After one afternoon, I finally found a way to delete database tables in batches...
This example uses the prefix xx _. You can change it to the table prefix you want to delete.
Copy codeThe Code is as follows:
<? Php
Function deldata ($ dbname, $ tableflag ){
$ Db_host = 'localhost ';
$ Db_port = '000000 ';
$ Db_user = 'user ';
$ Db_pass = 'Password ';
$ Connect = mysql_connect ($ db_host, $ db_user, $ db_pass );
Mysql_select_db ($ dbname );
$ Result = mysql_query ("show table status from $ dbname", $ connect );
$ Data = mysql_fetch_array ($ result );
While ($ data = mysql_fetch_array ($ result )){
$ Table = mysubstr ($ data [Name], "_");
If ($ table = $ tableflag ){
// Use for testing
/* Echo $ data [Name];
Echo"
";
Echo $ table;
Echo"
";*/
Mysql_query ("drop table $ data [Name]");
}
}
Return true;
}
/* Truncates all the character functions before a specific character
* $ Str is the string to be truncated.
* $ Flag specific characters such as "_"
*/
Function mysubstr ($ str, $ flag ){
$ Pos = strpos ($ str, $ flag );
Return substr ($ str, 0, $ pos );
}
?>
The change is:
1. Starting
<? Php
Function deldata ($ dbname, $ tableflag ){
$ Db_host = 'localhost ';
$ Db_port = '000000 ';
$ Db_user = 'user ';
$ Db_pass = 'Password ';
Change your database address, account, and password.
2. End
Change your database name and the table prefix you want to delete
You can copy the above Code and save it as. php, and upload it to the Space Directory to open it.