首页 > 数据库 > mysql中过期数据的自动删除代码

mysql中过期数据的自动删除代码

2009年04月05号
查看评论 发表评论 844次浏览

<?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>

类别数据库 标签,
  1. designer handbags outlet
    发表于 2010年06月18号 06时12分09秒 | 1楼

    Congratulations on your quest, sounds like it brough you back wonderful memories.

  2. herve leger dress
    发表于 2010年06月23号 11时03分29秒 | 2楼

    i hope so

  3. designer handbags replica
    发表于 2010年07月01号 09时55分45秒 | 3楼

    Thank You for a lovely story as always.

  4. kobe hyperdunk
    发表于 2010年07月21号 12时58分44秒 | 4楼

    Today is a gift and I will use it memorably way and thanks for reminding it once again

  1. 目前没有通告
你必需 登陆 才能发表评论.