PHP Bulk Delete the table with the prefix specified under the database prefix_ as an example _php skills

Source: Internet
Author: User

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

example, uniformly deletes a table prefixed with "prefix_".

<?php 
//Set up database connection information. Database server address, database user name, data password 
mysql_connect (' Database host ', ' Database username ', ' 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)) 
{ 
//Set 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 success! <br> "; 
}}} 
? >

Action Example:

Create a new PHP file and save it as a deletedata.php.
For example, to delete www.jb51.net or http://www.jb51.net/background data, operate two steps on OK:

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

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

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.