PHPCMS默认自带删除文章,但是一次最多只能删除20篇文章。如果要删除的文章数量多的话会很雷人,虽然我们可以通过删除栏目来实现删除文章,但是还是怕会删除的不彻底而占用数据库空间。
今天分享用代码达到彻底删除文章的目的吧!PHPCMS默认存储文章的数据表是v9_news和v9_news_data,一个是主表,用于存储文章的标题、描述、关键词等信息,另外个附表就主要是存储文章内容的。
<?php
$mydbhost = "localhost"; //配置主机
$mydbuser = "test"; //数据库用户
$mydbpw = "test2016#"; //数据库密码
$mydbname = "gongzheng"; //数据库名字
$mydbcharset = "utf8"; //设置编码
$link = mysql_connect($mydbhost,$mydbuser,$mydbpw) or die (mysql_error());
mysql_select_db($mydbname,$link) or die("没有该数据库:".$mydbname);
mysql_query("SET NAMES '$mydbcharset'");
$row= mysql_query("SELECT `a`.`id` as `k`,`b`.`id` as `p` FROM `v9_news` as `a` left join `v9_news_data` as `b` on `a`.`id` = `b`.`id` WHERE `a`.`catid` = '111' ORDER BY `a`.`id` DESC");
while ($rs=mysql_fetch_array($row)){
$aid = $rs[k];
$sql = "DELETE FROM `v9_news` WHERE `v9_news`.`id` = '$aid'";
$sql2 = "DELETE FROM `v9_news_data` WHERE `v9_news_data`.`id` = '$aid'";
mysql_query($sql);
mysql_query($sql2);
}
mysql_close();//关闭数据库连接
?>