When we maintain the site for updates, may be to delete the same database table operation is a headache, today we will explain to you specificallyPHP Delete database table specific implementation code is as follows
- 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 purposes
- /*echo $data [Name];
- echo "
- ";
- Echo $table;
- echo "
- ";*/
- mysql_query ("drop table $data [Name]");
- }
- }
- return true;
- }
- /* All character functions before a specific character is intercepted
- * $str for the string to be intercepted
- * $flag specific words such as "_"
- */
- function Mysubstr ($STR, $flag) {
- $ POS = Strpos ($str, $flag);
- Return substr ($str, 0, $pos);
- }
- ?>
- $ dbname = "Shujukuming" ;//Database name
- $ Tableflag = "XX" ;//prefix of the table to be deleted, the table with this prefix is deleted, which is the flag of which user
- Deldata ($dbname, $tableflag);
- //$ Test = Mysubstr ("Cdb_account_log", "_");
- Echo $test;
- ?>
PHP deletes the database table changes in:
1. At the beginning
- 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
- $ dbname = "Shujukuming" ;//Database name
- $ Tableflag = "XX" ;//prefix of the table to be deleted, the table with this prefix is deleted, which is the flag of which user
- Deldata ($dbname, $tableflag);
- //$ Test = Mysubstr ("Cdb_account_log", "_");
- Echo $test;
- ?>
You can complete the PHP delete database table by changing your database name and the table prefix you want to erase.
You can copy the above code to save as. php, and then upload to the spatial directory to open
It is recommended to download this. php file http://flysh.toypark.in//up/1255275586.umd After downloading the suffix to PHP, the name can be uploaded and opened.
http://www.bkjia.com/PHPjc/446309.html www.bkjia.com true http://www.bkjia.com/PHPjc/446309.html techarticle when we maintain the maintenance of the site, may be the deletion of the same database table operation is a headache, today we will explain to you specifically PHP Delete database table specific implementation code as follows ...