Php batch delete tables with the specified prefix in the database take prefix _ as an example. batch delete prefix_PHP tutorial

Source: Internet
Author: User
Php deletes tables with the specified prefix in a database in batches. the prefix _ is used as an example to delete tables with the specified prefix in batches. Php batch deletes tables with the specified prefix in the database. taking prefix _ as an example, how to batch delete tables with the prefix _ in the database using php. For example, if you delete a table with a specified prefix in a database in php batch, use prefix _ as an example to delete the prefix in batches.

How to use php to batch delete all tables prefixed with prefix _ in the database.

For example, delete all tables with the prefix "prefix.

<? Php // Set the database connection information. Database server address, database username, data password mysql_connect ('database host', 'database username ', 'database password '); // Set the queried database name 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!
";}}?>

Operation instance:

Create a new php file and save it as deletedata. php.
For example, if you want to delete the back-end data of www.jb51.net or http://www.bkjia.com/, you can perform the following two steps:

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

2. enter www.jb51.net/deletedata.php?http://www.bkjia.com/deletedata.php in the address bar.
The script displays information about the successful deletion of all tables in the browser.


Mysql databases batch delete data tables with the same prefix

Create a delete script first

Run the following statement:
Select 'drop table' + name from sysobjects where type = 'u' and name like 'B %'

The query results are displayed, and the query results are copied.
Then run the copied query results in database 123.

Mysql queries all tables with specific prefixes in a database.

Php won't.

In mysql, I will query the table information.

It is queried from information_schema.tables.

The following is an example:

Mysql> SELECT table_name, table_type, engine
-> FROM information_schema.tables
-> WHERE table_schema = 'test'
-> Order by table_name DESC;
-> //
+ -------------------- + ------------ + -------- +
| Table_name | table_type | engine |
+ -------------------- + ------------ + -------- +
| V_sale_report_x | VIEW | NULL |
| V_sale_report | VIEW | NULL |
| Union_tab_2 | base table | InnoDB |
| Union_tab_1 | base table | InnoDB |
| Test_trigger_table | base table | InnoDB |
| Test_tab2 | base table | InnoDB |
| Test_tab | base table | InnoDB |
| Test_main | base table | InnoDB |
| Test_dysql | base table | InnoDB |
| Test_create_tab4 | base table | InnoDB |
| Test_create_tab2 | base table | InnoDB |
| Test_create_tab1 | base table | InnoDB |
| Test_create_tab | base table | InnoDB |
| Sale_report | base table | InnoDB |
| Log_table | base table | InnoDB |
+ -------------------- + ------------ + -------- +
15 rows in set (0.02 sec)
 

How to use php to batch delete all tables prefixed with prefix _ in the database. For example, delete the prefix "...

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.