mysql中过期数据的自动删除代码
<?php
include(“./xajax/xajax.inc.php”);
$xajax=new xajax(); //利用xajax创建函数,便于函数被javascript调用
$xajax->decodeUTF8InputOn();
function checktime(){ //自动删除过期信息函数。
$obj=new xajaxresp****e();
$sql=”select id,lo from message”; //id代表数据库中对应行的标号;longtime:信息有效期,单位为 “天”; unix代表发表信息时的毫秒数
$rel=mysql_query($sql);
while($row=mysql_fetch_array($rel)) //对每条记录遍历
{
$time=getdate(); //取得当前时间
$b_time=$time[0]-$row[unix]; //取得当前时间与信息发布时之间的毫秒差
$b_day=$b_time/(1000*60*60*24); //将毫秒差转换为天数
if($b_day>=$row[longtime]) //比较天数是否超过了有效期,若是,则运行if语句下的自动删除程序
{
$sq=”delete * from message “; //自动删除过期信息
mysql_query($sq);
}
}
return $obj;
}$xajax->registerFunction(“checktime”); //注册函数
$xajax->processRequests();
?>
……………………
<head>
<script>
$xajax->printJavascript(“./xajax/”); 将函数写入xajax文件内
</script>
</head>
……………………
<body>
<script>
setInterval(“xajax_checktime”,84600000); //84600000毫秒代表一天,即每一天调用一次函数。
</script>
</body>
Congratulations on your quest, sounds like it brough you back wonderful memories.
i hope so
Thank You for a lovely story as always.
Today is a gift and I will use it memorably way and thanks for reminding it once again