public function del_data7($param1=''){
if($param1){
$timestamp=$this->get_timestamp($param1,'Ymd');
}else{
$hour=isset($_SERVER['argv'][2])?$_SERVER['argv'][2]:date('Ymd',strtotime('-8 day'));
$timestamp=$this->get_timestamp($hour,'Y-m-d');
}
$starttime=$timestamp*1000;
$endtime=($timestamp+24*60*60)*1000-1;
$default_date=date('Ymd', $timestamp);
$log_table_name=log_name();
$zhuijia=array(
);
$new_arr=array_merge($log_table_name,$zhuijia);
$where=" time<={$endtime} and time >= {$starttime} ";
foreach ($new_arr as $v){
$table_bool=$this->mysql_exec(config('database_log.log'),$v['item'],$default_date,$where);
if($table_bool==true){
$sql=" delete from ".config('database_log.log').".{$v['item']} where {$where} ";
echo Db::execute($sql).$v['item']."成功\r\n";
}else{
//echo config('database_log.log'),$v['item'],$default_date,$where;
echo config('database_log.log'),$v['item'],$default_date,$where."失败\r\n";
}
}
$log_fenbiao=$this->log_fenbiao;
foreach ($log_fenbiao as $v){
$table_bool=$this->mysql_exec(config('database_log.log'),$v,$default_date);
if($table_bool==true) {
//$this->delTable(config('database_log.log'), $v, $default_date);
echo $this->delTable(config('database_log.log'), $v, $default_date).config('database_log.log').$v.$default_date."分表成功\r\n";
}else{
echo config('database_log.log'),$v,$default_date."失败\r\n";
}
}
}
public function delTable($db,$tableName = 'login_logout',$default_date=''){
$tableTarget=$tableName.$default_date;
if (Db::query(" select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='{$db}' and TABLE_NAME='{$tableTarget}' ")) {
return Db::execute(" delete from {$db}.{$tableTarget} ");
}
}
public function mysql_exec($db,$table,$date,$where=''){
$file="./".$table.$date.".sql";
if(file_exists($file)&&strpos(file_get_contents($file),"Dump completed on") !== false) {
return true;
}
if($where==''){
$exec_where="";
}else{
$exec_where=" --no-create-info --skip-extended-insert --where=\" {$where} \"";
}
$exec=" mysqldump -uroot -proot {$db} {$table} {$exec_where} > {$file}";
exec($exec);
if(file_exists($file)&&strpos(file_get_contents($file),"Dump completed on") !== false) {
return true;
}
return false;
/*$hd = fopen($file, 'rb');
echo fread($hd, filesize($file));
fclose($hd);*/
}
php每日备份mysql数据库
最新推荐文章于 2024-11-08 16:00:10 发布