In-depth discussion on how to delete database tables in PHP _ PHP Tutorial

Source: Internet
Author: User
This article explores how PHP deletes database tables. When we update and maintain the website, it may be a headache to delete the same database tables, today, we will explain to you how to delete a database table in PHP. the specific implementation code is as follows. when we update and maintain the website, it may be a headache to delete the same database table, today, we will give you a detailed explanation.The PHP code for deleting a database table is as follows:

 
 
  1. Function deldata ($ dbname, $ tableflag ){
  2. $ Db_host = 'localhost ';
  3. $ Db_port = '000000 ';
  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. // Use for testing
  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. /* Truncates all the character functions before a specific character
  26. * $ Str is the string to be truncated.
  27. * $ Flag specific characters 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"; // the prefix of the table to be deleted. only tables with this prefix are deleted, indicating which user
  3. Deldata ($ dbname, $ tableflag );
  4. // $ Test = mysubstr ("cdb_account_log ","_");
  5. // Echo $ test;
  6. ?>

PHP deletes the database table:

1. starting

 
 
  1. function deldata($dbname,$tableflag){
  2. $db_host = 'localhost';
  3. $db_port = '3306';
  4. $db_user = 'user';
  5. $db_pass = 'password';

Change your database address, account, and password.

2. end

 
 
  1. $ Dbname = "shujukuming"; // database name
  2. $ Tableflag = "xx"; // the prefix of the table to be deleted. only tables with this prefix are deleted, indicating which user
  3. Deldata ($ dbname, $ tableflag );
  4. // $ Test = mysubstr ("cdb_account_log ","_");
  5. // Echo $ test;
  6. ?>

You can delete a database table in PHP by changing the database name and the table prefix you want to delete.
You can copy the above code and save it as. php, and upload it to the space directory to open it.
We recommend that you download the. php file ghost.


The specific implementation code for deleting a database table in connector PHP is as follows...

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.