How does PHP bulk delete tables with specified prefixes under the database?

Source: Internet
Author: User

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

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

<?php

Sets the database connection information. Database server address, database user name, data password

mysql_connect (' Database host ', ' Database user name ', ' Database Password ');

Set the database name for the query

mysql_select_db (' database name ');

$rs =mysql_query (' Show Tables ');

while ($arr =mysql_fetch_array ($RS))

{www.jbxue.com

Set the database table prefixes 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] Delete succeeded! <br> ";

}

}

}

?>

Operation Example:

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

For example, to delete www.jbxue.com or http://www.jbxue.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.jbxue.com/deletedata.php or http://www.jbxue.com/deletedata.php execute this delete script.

The script displays information about all table deletion successes in the browser.

How does PHP bulk delete tables with specified prefixes under the database?

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.