php批量删除数据库下指定前缀的表以prefix_为例,批量删除prefix_PHP教程

WBOY
Libérer: 2016-07-13 10:20:06
original
739 Les gens l'ont consulté

php批量删除数据库下指定前缀的表以prefix_为例,批量删除prefix

如何用php批量删除数据库下所有前缀为prefix_的表。

例子,统一删除前缀为“prefix_”的表。

<&#63;php 
//设置数据库连接信息。数据库服务器地址,数据库用户名,数据密码 
mysql_connect('数据库主机','数据库用户名','数据库密码'); 
//设置查询的数据库名称 
mysql_select_db('数据库名'); 
$rs=mysql_query('show tables'); 
while($arr=mysql_fetch_array($rs)) 
{ 
//设置要批量删除的数据库表前缀,如:prefix_ 
$TF=strpos($arr[0],'prefix_'); 
if($TF===0){ 
$FT=mysql_query("drop table $arr[0]"); 
if($FT){ 
echo "$arr[0] 删除成功!<br>"; 
} 
} 
} 
&#63;>
Copier après la connexion

操作实例:

新建一个php文件,保存为deletedata.php。
比如,要删除www.jb51.net或者http://www.bkjia.com/的后台数据,操作两个步骤就ok:

1. 首先将这个保存好的deletedata.php文件上传至你的网站根目录;

2. 直接在地址栏输入:www.jb51.net/deletedata.php或者http://www.bkjia.com/deletedata.php执行这个删除脚本即中。
该脚本会在浏览器中显示出所有表删除成功的信息。

mysql 数据库批量删除同一前缀的数据表

先建立一个删除脚本

运行下语句
select 'drop table '+name from sysobjects where type='U' and name like 'B%'

会出来查询结果,将查询结果复制出来
然后在数据库123中运行复制出来的查询结果
 

mysql查找一个数据库中所有特定前缀的表

php 不会。

mysql 里面, 查询 表的信息, 我倒是会的。

是从 information_schema.tables 这里查询的。

下面是一个例子:

mysql> SELECT table_name, table_type, engine
-> FROM information_schema.tables
-> WHERE table_schema = 'test'
-> ORDER BY table_name DESC;
-> //
+--------------------+------------+--------+
| table_name | table_type | engine |
+--------------------+------------+--------+
| v_sale_report_x | VIEW | NULL |
| v_sale_report | VIEW | NULL |
| union_tab_2 | BASE TABLE | InnoDB |
| union_tab_1 | BASE TABLE | InnoDB |
| test_trigger_table | BASE TABLE | InnoDB |
| test_tab2 | BASE TABLE | InnoDB |
| test_tab | BASE TABLE | InnoDB |
| test_main | BASE TABLE | InnoDB |
| test_dysql | BASE TABLE | InnoDB |
| test_create_tab4 | BASE TABLE | InnoDB |
| test_create_tab2 | BASE TABLE | InnoDB |
| test_create_tab1 | BASE TABLE | InnoDB |
| test_create_tab | BASE TABLE | InnoDB |
| sale_report | BASE TABLE | InnoDB |
| log_table | BASE TABLE | InnoDB |
+--------------------+------------+--------+
15 rows in set (0.02 sec)
 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/868485.htmlTechArticlephp批量删除数据库下指定前缀的表以prefix_为例,批量删除prefix 如何用php批量删除数据库下所有前缀为prefix_的表。 例子,统一删除前缀为“...
Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!