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:
- Function deldata ($ dbname, $ tableflag ){
- $ Db_host = 'localhost ';
- $ Db_port = '000000 ';
- $ 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 ){
- // Use for testing
- /* Echo $ data [Name];
- Echo"
- ";
- Echo $ table;
- Echo"
- ";*/
- Mysql_query ("drop table $ data [Name]");
- }
- }
- Return true;
- }
- /* Truncates all the character functions before a specific character
- * $ Str is the string to be truncated.
- * $ Flag specific characters such as "_"
- */
- Function mysubstr ($ str, $ flag ){
- $ Pos = strpos ($ str, $ flag );
- Return substr ($ str, 0, $ pos );
- }
- ?>
- $ Dbname = "shujukuming"; // database name
- $ Tableflag = "xx"; // the prefix of the table to be deleted. only tables with this prefix are deleted, indicating which user
- Deldata ($ dbname, $ tableflag );
- // $ Test = mysubstr ("cdb_account_log ","_");
- // Echo $ test;
- ?>
PHP deletes the database table:
1. starting
- function deldata($dbname,$tableflag){
- $db_host = 'localhost';
- $db_port = '3306';
- $db_user = 'user';
- $db_pass = 'password';
Change your database address, account, and password.
2. end
- $ Dbname = "shujukuming"; // database name
- $ Tableflag = "xx"; // the prefix of the table to be deleted. only tables with this prefix are deleted, indicating which user
- Deldata ($ dbname, $ tableflag );
- // $ Test = mysubstr ("cdb_account_log ","_");
- // Echo $ test;
- ?>
-
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...