先在数据库里查询,数据库里有多少篇这样的文章
SELECT aid FROM dede_addonarticle WHERE LENGTH(body)<50;
效果图:
<meta charset="utf-8">
<?php
$host = '127.0.0.1';
$user = 'root';
$pwd = '123456';
$name = 'dede';
@$mysqli = new mysqli($host,$user,$pwd,$name);
if (mysqli_connect_errno ()) {
echo '数据库连接出现了错误';
exit ();
}
$mysqli->set_charset ('utf8');
$sql = "SELECT aid FROM dede_addonarticle WHERE LENGTH(body)<50";
$result = $mysqli->query($sql);
$arr = array();
$i = 0;
while (!!$row = $result->fetch_row()) {
$arr[$i]=$row[0];
$i++;
}
//print_r($arr);
$str="";
$str2="";
for($i=0;$i<count($arr);$i++){
if($i===(count($arr)-1)){
$str.= "aid = $arr[$i]";
$str2.= "id = $arr[$i]";
}else{
$str.= "aid = $arr[$i] OR ";
$str2.= "id = $arr[$i] OR ";
}
}
echo 'DELETE FROM dede_addonarticle WHERE '.$str.';';
echo '<br>';
echo 'DELETE FROM dede_arctiny WHERE '.$str2.';';
echo '<br>';
echo 'DELETE FROM dede_archives WHERE '.$str2.';';
$mysqli->close();
?>
效果图:
然后把这些语句执行,效果图:
标签:arr,字节,DEDE,dede,50,echo,str2,WHERE,row From: https://blog.51cto.com/u_16171388/6558652