Use php to batch Delete All Tables prefixed with prefix _ in the database

Source: Internet
Author: User
This article mainly introduces how php batch deletes all tables prefixed with prefix _ in the database. For more information, see

This article mainly introduces how php batch deletes all tables prefixed with prefix _ in the database. For more information, see

The following is a script to delete a table prefixed with "prefix:

The Code is as follows:


// Set the database connection information. Database server address, database user name, data Password
Mysql_connect ('database host', 'database username', 'database password ');
// Set the name of the queried Database
Mysql_select_db ('database name ');
$ Rs = mysql_query ('show tables ');
While ($ arr = mysql_fetch_array ($ rs ))
{
// Set the database table prefix to be deleted in batches, for example, prefix _
$ TF = strpos ($ arr [0], 'prefix _');
If ($ TF = 0 ){
$ FT = mysql_query ("drop table $ arr [0]");
If ($ FT ){
Echo "$ arr [0] deleted successfully!
";
}
}
}
?>


Create a new php file and save it as deletedata. php

For example, if you want to delete or background data, perform the following two steps:

1. Upload the saved deletedata. php file to the root directory of your website;

2. directly enter in the address bar: or execute the delete script to check whether the script is successfully deleted.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.