专注于高品质PHP技术等信息服务于一体 [STIEMAP] [RSS]

百度提供的广告:
PHP
当前位置:首页 > 技术文档 > PHP >  > 
PHPCMS2008SP4 文章url丢失修复程序

<?php
/**
 * PHPCMS2008SP4 文章url丢失修复程序
 * 作者:清如许 时间:2011-03-16
 * 修复原理:
 * 1,查询所有栏目 id 保存路径  select * from phpcms_category;
 * 2,查询所有文章,根据 catid = 以上ID
 * 3,更新文章url
 */
 set_time_limit(0);
 mysql_connect("localhost","root","123456");
 mysql_select_db("phpcms2");
 $categoryRs=mysql_query(" select catid,url from phpcms_category ;");
 $categoryArr=array();
 while($row = mysql_fetch_array($categoryRs))
 {
    array_push($categoryArr,$row);
 }
 //已查到栏目数据
 $newArcArr = array();
 foreach ($categoryArr as $category){
     $sql=" select contentid,url from phpcms_content  where islink=0 and catid=".$category['catid'];
    $arcRs= mysql_query($sql);
    if(!is_resource($arcRs)) continue;
    $arcArr=array();
    while($arcRow=mysql_fetch_array($arcRs)){
      array_push($arcArr,$arcRow);
    }
    //查询到每个栏目下具体文章id url
    foreach ($arcArr as $arr){
      $newArcArr[]=array('contentid'=>$arr['contentid'],'url'=>$category['url'].$arr['contentid'].'html');
    }
    //已重新更新
   
 }
 $sql ="";
 foreach ($newArcArr as $arr)
 {
     mysql_query(" update phpcms_content set url='".$arr['url']."' where contentid=".$arr['contentid']);
 }
 echo "已修复".count($newArcArr);
?>