PHP Bulk Delete Database under the specified prefix table with Prefix_ as an example, bulk delete prefix_php tutorial

Source: Internet
Author: User

PHP Bulk Delete Database under the specified prefix table with Prefix_ as an example, bulk delete prefix


How to use PHP to bulk delete all tables prefixed with prefix_ in the database.

example, uniformly remove the table prefixed with "prefix_".

<?php//Set database connection information. Database server address, database user name, data password mysql_connect (' Database host ', ' Database user name ', ' Database Password '); Set the database name of the query mysql_select_db (' database name '); $rs =mysql_query (' Show Tables '); while ($arr =mysql_fetch_array ($rs)) {//sets the database table prefix to be deleted in bulk, such as: Prefix_ $TF =strpos ($arr [0], ' prefix_ '); if ($TF ===0) {$FT = mysql_query ("drop table $arr [0]"); if ($FT) {echo "$arr [0] deleted successfully!
"; } } } ? >

Operation Example:

Create a new PHP file and save it as deletedata.php.
For example, to delete www.jb51.net or http://www.bkjia.com/background data, the operation of two steps is OK:

1. First upload this saved deletedata.php file to your website root directory;

2. Enter directly in the Address bar: www.jb51.net/deletedata.php or http://www.bkjia.com/deletedata.php execute this delete script.
The script displays information about all table deletion successes in the browser.


MySQL Database bulk delete data table with same prefix

Create a Delete script first

Run the Next statement
Select ' Drop table ' +name from sysobjects where type= ' U ' and name like ' B% '

Will come out to query the results, copy the query results
Then run the replicated query results in database 123

MySQL finds a table of all specific prefixes in a database

PHP does not.

MySQL inside, query the information of the table, I will.

is from Information_schema.tables here.

Here 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 |
+--------------------+------------+--------+
Rows in Set (0.02 sec)

http://www.bkjia.com/PHPjc/868485.html www.bkjia.com true http://www.bkjia.com/PHPjc/868485.html techarticle PHP Bulk Delete database under the specified prefix table with Prefix_ as an example, bulk delete prefix how to bulk delete the database under the prefix_ of all the tables under the prefix. example, the unified delete prefix is "...

  • 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.