DelCam.pl
上传用户:qdrechuli
上传日期:2022-08-01
资源大小:917k
文件大小:1k
- #!/usr/bin/perl -w
- use strict;
- use DBI;
- use LWP::UserAgent;
- use vars qw(%base);
- sub DelCam
- {
- (my $CID,my $CAge) = @_;
- print "CID = ",$CID," CAge = ",$CAge,"n";
- (my $sec,my $min,my $hour,my $mday,my $mon,my $year,my $wday,my $yday,my $isdst) = localtime(time-$CAge*60*60*24);
- $year = $year+1900;
- $mon = $mon+1;
- my $smon;
- my $smday;
- if ($mon<10) { $smon = "0".$mon; }
- if ($mon>9) { $smon = $mon; }
- if ($mday<10) { $smday = "0".$mday; }
- if ($mday>9) { $smday = $mday; }
- my $tranche = $year.$smon.$smday;
- print $tranche,"n";
- my $db = DBI->connect("DBI:mysql:netcam","root","");
- my $sqlreq = "DELETE FROM record WHERE R_CAM=".$CID." AND R_Day<'".$tranche."'";
- my $sql = $db->prepare($sqlreq);
- $sql->execute();
- $sql->finish();
- $db->disconnect();
- }
-
- sub main
- {
- my $db = DBI->connect("DBI:mysql:netcam","root","");
- my $sqlreq = "SELECT C_ID,C_Age FROM cam ";
- my $sql = $db->prepare($sqlreq);
- $sql->execute();
- while ((my $CID,my $CAge) = $sql->fetchrow())
- {
- DelCam($CID,$CAge);
- }
- $sql->finish();
- $db->disconnect();
- }
-
- main();