In-depth discussion of how PHP deletes database tables _php tutorial

Source: Internet
Author: User
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

 
 
  1. function Deldata ($dbname, $tableflag) {
  2. $ Db_host = ' localhost ' ;
  3. $ Db_port = ' 3306 ' ;
  4. $ Db_user = ' user ' ;
  5. $ Db_pass = ' Password ' ;
  6. $ Connect = mysql_connect ($db _host, $db _user, $db _pass);
  7. mysql_select_db ($dbname);
  8. $ result = mysql_query ("Show Table status from $dbname", $connect);
  9. $ Data = Mysql_fetch_array ($result);
  10. While ($data=mysql_fetch_array($result)) {
  11. $ Table = Mysubstr ($data [Name], "_");
  12. if ($table= = $tableflag) {
  13. For testing purposes
  14. /*echo $data [Name];
  15. echo "
  16. ";
  17. Echo $table;
  18. echo "
  19. ";*/
  20. mysql_query ("drop table $data [Name]");
  21. }
  22. }
  23. return true;
  24. }
  25. /* All character functions before a specific character is intercepted
  26. * $str for the string to be intercepted
  27. * $flag specific words such as "_"
  28. */
  29. function Mysubstr ($STR, $flag) {
  30. $ POS = Strpos ($str, $flag);
  31. Return substr ($str, 0, $pos);
  32. }
  33. ?>

 
  
  
  1. $ dbname = "Shujukuming" ;//Database name
  2. $ Tableflag = "XX" ;//prefix of the table to be deleted, the table with this prefix is deleted, which is the flag of which user
  3. Deldata ($dbname, $tableflag);
  4. //$ Test = Mysubstr ("Cdb_account_log", "_");
  5. Echo $test;
  6. ?>

PHP deletes the database table changes in:

1. At the beginning

 
  
  
  1. function Deldata ($dbname, $tableflag) {
  2. $ Db_host ' localhost ';
  3. $ Db_port ' 3306 ';
  4. $ Db_user ' user ';
  5. $ Db_pass ' password ';

Change to your database address, account number and password.

2. At the end

 
  
  
  1. $ dbname = "Shujukuming" ;//Database name
  2. $ Tableflag = "XX" ;//prefix of the table to be deleted, the table with this prefix is deleted, which is the flag of which user
  3. Deldata ($dbname, $tableflag);
  4. //$ Test = Mysubstr ("Cdb_account_log", "_");
  5. Echo $test;
  6. ?>

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

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