新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
php中批量刪除Mysql中相同前綴的數(shù)據(jù)表
用php開發(fā)程序時,批量刪除相同前綴的數(shù)據(jù)表的兩種方法如下:

創(chuàng)新互聯(lián)公司專注于企業(yè)成都全網(wǎng)營銷、網(wǎng)站重做改版、邯鄲網(wǎng)站定制設(shè)計、自適應(yīng)品牌網(wǎng)站建設(shè)、H5網(wǎng)站設(shè)計、商城網(wǎng)站建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、外貿(mào)營銷網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計等建站業(yè)務(wù),價格優(yōu)惠性價比高,為邯鄲等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
方法一:
復(fù)制代碼 代碼如下:
- mysql_connect('','','');
- mysql_select_db('');
- $rs=mysql_query('show tables');
- while($arr=mysql_fetch_array($rs)){
- $TF=strpos($arr[0],'class_');
- if($TF===0){
- $FT=mysql_query("drop table $arr[0]");
- if($FT){
- echo "$arr[0] 刪除成功!
";- }
- }
- }
- ?>
方法二:
這個是以xx_為前綴的示范,大家可以自己更改為想刪除的表前綴。
復(fù)制代碼 代碼如下:
- 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){
- //測試之用
- /*echo $data[Name];
- echo "
- ";
- echo $table;
- echo "
- ";*/
- mysql_query("drop table $data[Name]");
- }
- }
- return true;
- }
- /*截取某個特定字符前的所有字符函數(shù)
- *$str 為待截取字符串
- *$flag 特定字符如"_"
- */
- function mysubstr($str,$flag){
- $pos=strpos($str,$flag);
- return substr($str,0,$pos);
- }
- ?>
更改之處在:
1.開頭處
- function deldata($dbname,$tableflag){
- $db_host = 'localhost';
- $db_port = '3306';
- $db_user = 'user';
- $db_pass = 'password';
改為自己的數(shù)據(jù)庫地址,賬號和密碼即可。
2.結(jié)尾處
改為自己的數(shù)據(jù)庫名和想刪掉的表前綴。
可以復(fù)制上面的代碼保存為.php,再上傳到空間目錄打開。這樣我們就能完成數(shù)據(jù)表的批量刪除了。
新聞標(biāo)題:php中批量刪除Mysql中相同前綴的數(shù)據(jù)表
當(dāng)前URL:http://m.fisionsoft.com.cn/article/dpccpec.html


咨詢
建站咨詢
