dedecms 数据库同步代码

因为数据库需要同步,无奈之下出此方法,本地数据库向外数据库提交数据
1.188服务器需要开启远程连接权限
2.两个数据库必须结构必须一致(我是把本地数据库备份到远程的)
3.创建php同步文件,添加到linux自动任务里


下面是php源码

//连接本地130数据库
	$cont130=mysql_connect("100.100.100.30","root","root")or die("mysql连接失败");
	mysql_select_db("cms",$cont130)or die("db连接失败");
	mysql_query("SET NAMES gbk",$cont130);
//end

//连接188服务器数据库
    $cont188=mysql_connect("100.100.100.188","root","root", true)or die("mysql连接失败");
	mysql_select_db("jinghuadb",$cont188)or die("db连接失败");
	mysql_query("SET NAMES gbk",$cont188);
//end

//查找表130内最大ID
	$sql130 = "select * from jh_addonimages order by aid desc limit 0,1";
	$quer130 = mysql_query($sql130,$cont130);
	$array130 = mysql_fetch_array($quer130);
	
//查找表188内最大ID
	
	$sql188 = "select * from jh_addonimages order by aid desc limit 0,1";
	//测试表2:$sql188 = "select * from jh_archives order by id desc limit 0,1";
	//测试表3:$sql188 = "select * from jh_arctiny order by id desc limit 0,1";

	$quer188 = mysql_query($sql188,$cont188);
	$array188 = mysql_fetch_array($quer188);	

//获取开始ID和结束ID 固定id 其他两个表也使用此ID 防止数据对应不上 
	$startid = $array188['aid'];
	//测试表:$startid = $array188['id'];
	$endid = $array130['aid'];

//判断是否有更新 如果没有更新就暂停
if($startid == $endid){ echo "mysql not update"; mysql_close($cont188);mysql_close($cont130); die();}


//数据表jh_addonimages同步
	$sql130 = "select * from jh_addonimages where aid <= $endid and aid >$startid";

	$quer130 = mysql_query($sql130,$cont130);
	while($array130 = mysql_fetch_array($quer130)){

			$aid = addslashes($array130['aid']);
			$typeid = addslashes($array130['typeid']);
			$pagestyle = addslashes($array130['pagestyle']);
			$maxwidth = addslashes($array130['maxwidth']);
			$imgurls = addslashes($array130['imgurls']);
			$row = addslashes($array130['row']);
			$col = addslashes($array130['col']);
			$isrm = addslashes($array130['isrm']);
			$ddmaxwidth = addslashes($array130['ddmaxwidth']);
			$pagepicnum = addslashes($array130['pagepicnum']);
			$templet = addslashes($array130['templet']);
			$userip = addslashes($array130['userip']);
			$redirecturl = addslashes($array130['redirecturl']);
			$body = addslashes($array130['body']);


			$sql188 = "INSERT INTO jh_addonimages(aid, typeid, pagestyle, maxwidth,imgurls,row,col,isrm,ddmaxwidth,pagepicnum,templet,userip,redirecturl,body)VALUES('$aid','$typeid','$pagestyle','$maxwidth','$imgurls','$row','$col','$isrm','$ddmaxwidth','$pagepicnum','$templet','$userip','$redirecturl','$body')";
			mysql_query($sql188,$cont188) or die("Error in query: $query. ".mysql_error());

	}


//数据表jh_archives同步
	$arcsql130 = "select * from jh_archives where id <= $endid and id >$startid";
	$arcquer130 = mysql_query($arcsql130,$cont130);
	while($array130 = mysql_fetch_array($arcquer130)){
			$id = addslashes($array130['id']);
			$typeid = addslashes($array130['typeid']);
			$typeid2 = addslashes($array130['typeid2']);
			$sortrank = addslashes($array130['sortrank']);
			$flag = addslashes($array130['flag']);
			$ismake = addslashes($array130['ismake']);
			$channel = addslashes($array130['channel']);
			$arcrank = addslashes($array130['arcrank']);
			$click = addslashes($array130['click']);
			$money = addslashes($array130['money']);
			$title = addslashes($array130['title']);
			$shorttitle = addslashes($array130['shorttitle']);
			$color = addslashes($array130['color']);
			$writer = addslashes($array130['writer']);
			$source = addslashes($array130['source']);
			$litpic = addslashes($array130['litpic']);
			$pubdate = addslashes($array130['pubdate']);
			$senddate = addslashes($array130['senddate']);
			$mid = addslashes($array130['mid']);
			$keywords = addslashes($array130['keywords']);
			$lastpost = addslashes($array130['lastpost']);
			$scores = addslashes($array130['scores']);
			$goodpost = addslashes($array130['goodpost']);
			$badpost = addslashes($array130['badpost']);
			$voteid = addslashes($array130['voteid']);
			$notpost = addslashes($array130['notpost']);
			$description = addslashes($array130['description']);
			$filename = addslashes($array130['filename']);
			$dutyadmin = addslashes($array130['dutyadmin']);
			$tackid = addslashes($array130['tackid']);
			$mtype = addslashes($array130['mtype']);
			$weight = addslashes($array130['weight']);
			$yurl = addslashes($array130['yurl']);

			$sql188 = "INSERT INTO jh_archives(id,typeid,typeid2,sortrank,flag,ismake,channel,arcrank,click,money,title,shorttitle,color,writer,source,litpic,pubdate,senddate,mid,keywords,lastpost,scores,goodpost,badpost,voteid,notpost,description,filename,dutyadmin,tackid,mtype,weight,yurl)VALUES('$id','$typeid','$typeid2','$sortrank','$flag','$ismake','$channel','$arcrank','$click','$money','$title','$shorttitle','$color','$writer','$source','$litpic','$pubdate','$senddate','$mid','$keywords','$lastpost','$scores','$goodpost','$badpost','$voteid','$notpost','$description','$filename','$dutyadmin','$tackid','$mtype','$weight','$yurl')";
			mysql_query($sql188,$cont188) or die("Error in query: $query. ".mysql_error());

	}


//数据表jh_arctiny 同步
	$arctiny130 = "select * from jh_arctiny  where id <= $endid and id >$startid";
	$arctinyquer130 = mysql_query($arctiny130,$cont130);
	while($array130 = mysql_fetch_array($arctinyquer130)){
			$id = addslashes($array130['id']);
			$typeid = addslashes($array130['typeid']);
			$typeid2 = addslashes($array130['typeid2']);
			$arcrank = addslashes($array130['arcrank']);
			$channel = addslashes($array130['channel']);
			$senddate = addslashes($array130['senddate']);
			$sortrank = addslashes($array130['sortrank']);
			$mid = addslashes($array130['mid']);

		

			$sql188 = "INSERT INTO jh_arctiny(id,typeid,typeid2,arcrank,channel,senddate,sortrank,mid)VALUES('$id','$typeid','$typeid2','$arcrank','$channel','$senddate','$sortrank','$mid')";
			mysql_query($sql188,$cont188) or die("Error in query: $query. ".mysql_error());
	}
echo "the data update OK";
 mysql_close($cont188);
 mysql_close($cont130);

dedecms 单独自动更新某个列表页

1.需要给这个列表页面单独做一个模版
2.写php文件 write_list.php 代码如下

require_once(dirname(__FILE__)."/../include/common.inc.php");
require_once(dirname(__FILE__)."/../include/arc.partview.class.php"); 
$pv = new PartView();
$pv->SetTemplet(dirname(__FILE__)."/../templets/default/write_list.htm");
$pv->SaveToHtml("/html/xinwen/write_list.shtml");
$pv->Close(); 

3.linux自动定时文件 write_list.php