Code _php tips for bulk deletion of data tables in MySQL with the same prefix in PHP

Source: Internet
Author: User
Method One:
Copy Code code as follows:

<?php
Mysql_connect (', ', ', ');
mysql_select_db (");
$rs =mysql_query (' Show Tables ');
while ($arr =mysql_fetch_array ($rs)) {
$TF =strpos ($arr [0], ' class_ ');
if ($TF ===0) {
$FT =mysql_query ("drop table $arr [0]");
if ($FT) {
echo "$arr [0] Delete success! <br> ";
}
}
}
?>


Method Two:
Today to reload a station, engaged in the afternoon, finally found a can be used to delete the database table method ...
This is a xx_-prefix demonstration, you can change yourself to delete the table prefix
Copy Code code as follows:

<?php
function Deldata ($dbname, $tableflag) {
$db _host = ' localhost ';
$db _port = ' 3306 ';
$db _user = ' user ';
$db _pass = ' password ';
$connect =mysql_connect ($db _host, $db _user, $db _pass);
mysql_select_db ($dbname);
$result = mysql_query ("Show Table status from $dbname", $connect);
$data =mysql_fetch_array ($result);
while ($data =mysql_fetch_array ($result)) {
$table =mysubstr ($data [Name], "_");
if ($table = = $tableflag) {
For testing
/*echo $data [Name];
echo "
";
Echo $table;
echo "
";*/
mysql_query ("drop table $data [Name]");
}
}
return true;
}
/* All character functions prior to intercepting a particular character
* $STR to intercept string
* $flag Specific characters Furu "_"
*/
function Mysubstr ($STR, $flag) {
$pos =strpos ($str, $flag);
Return substr ($str, 0, $pos);
}
?>

The change is in:
1. At the beginning

<?php
function Deldata ($dbname, $tableflag) {
$db _host = ' localhost ';
$db _port = ' 3306 ';
$db _user = ' user ';
$db _pass = ' password ';
Change to your database address, account number and password
2. At the end

Change to your database name and the table prefix you want to delete
You can copy the above code to save it as. php and upload it to the space directory.
Related Article

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.