备份navicat数据库连接信息,导入后需要输入密码才可以连接数据库

<?php
class NavicatPassword
{
    protected $version = 0;
    protected $aesKey = 'libcckeylibcckey';
    protected $aesIv = 'libcciv libcciv ';
    protected $blowString = '3DC5CA39';
    protected $blowKey = null;
    protected $blowIv = null;
     
    public function __construct($version = 12)
    {
        $this->version = $version;
        $this->blowKey = sha1('3DC5CA39', true);
        $this->blowIv = hex2bin('d9c7c3c8870d64bd');
    }
     
    public function encrypt($string)
    {
        $result = FALSE;
        switch ($this->version) {
            case 11:
                $result = $this->encryptEleven($string);
                break;
            case 12:
                $result = $this->encryptTwelve($string);
                break;
            default:
                break;
        }
         
        return $result;
    }
     
    protected function encryptEleven($string)
    {
        $round = intval(floor(strlen($string) / 8));
        $leftLength = strlen($string) % 8;
        $result = '';
        $currentVector = $this->blowIv;
         
        for ($i = 0; $i < $round; $i++) {
            $temp = $this->encryptBlock($this->xorBytes(substr($string, 8 * $i, 8), $currentVector));
            $currentVector = $this->xorBytes($currentVector, $temp);
            $result .= $temp;
        }
         
        if ($leftLength) {
            $currentVector = $this->encryptBlock($currentVector);
            $result .= $this->xorBytes(substr($string, 8 * $i, $leftLength), $currentVector);
        }
         
        return strtoupper(bin2hex($result));
    }
     
    protected function encryptBlock($block)
    {
        return openssl_encrypt($block, 'BF-ECB', $this->blowKey, OPENSSL_RAW_DATA|OPENSSL_NO_PADDING);
    }
     
    protected function decryptBlock($block)
    {
        return openssl_decrypt($block, 'BF-ECB', $this->blowKey, OPENSSL_RAW_DATA|OPENSSL_NO_PADDING);
    }
     
    protected function xorBytes($str1, $str2)
    {
        $result = '';
        for ($i = 0; $i < strlen($str1); $i++) {
            $result .= chr(ord($str1[$i]) ^ ord($str2[$i]));
        }
         
        return $result;
    }
     
    protected function encryptTwelve($string)
    {
        $result = openssl_encrypt($string, 'AES-128-CBC', $this->aesKey, OPENSSL_RAW_DATA, $this->aesIv);
        return strtoupper(bin2hex($result));
    }
     
    public function decrypt($string)
    {
        $result = FALSE;
        switch ($this->version) {
            case 11:
                $result = $this->decryptEleven($string);
                break;
            case 12:
                $result = $this->decryptTwelve($string);
                break;
            default:
                break;
        }
         
        return $result;
    }
     
    protected function decryptEleven($upperString)
    {
        $string = hex2bin(strtolower($upperString));
         
        $round = intval(floor(strlen($string) / 8));
        $leftLength = strlen($string) % 8;
        $result = '';
        $currentVector = $this->blowIv;
         
        for ($i = 0; $i < $round; $i++) {
            $encryptedBlock = substr($string, 8 * $i, 8);
            $temp = $this->xorBytes($this->decryptBlock($encryptedBlock), $currentVector);
            $currentVector = $this->xorBytes($currentVector, $encryptedBlock);
            $result .= $temp;
        }
         
        if ($leftLength) {
            $currentVector = $this->encryptBlock($currentVector);
            $result .= $this->xorBytes(substr($string, 8 * $i, $leftLength), $currentVector);
        }
         
        return $result;
    }
     
    protected function decryptTwelve($upperString)
    {
        $string = hex2bin(strtolower($upperString));
        return openssl_decrypt($string, 'AES-128-CBC', $this->aesKey, OPENSSL_RAW_DATA, $this->aesIv);
    }
};
//需要指定版本两种,11或12
//$navicatPassword = new NavicatPassword(12);
$navicatPassword = new NavicatPassword(11);
//解密
$decode = $navicatPassword->decrypt('53DC5F1A62D25A5E78E7');
echo $decode."\n";
?>

月初到月末时间戳

<?php
    $y = date("Y", time()); //年 
    $m = date("m", time()); //月 
    $d = date("d", time()); //日 
    $t0 = date('t'); // 本月一共有几天 
    $start_month = mktime(0, 0, 0, $m, 1, $y); // 本月开始时间戳
    $end_month = mktime(23, 59, 59, $m, $t0, $y); // 本月结束时间戳

时间戳相关

<?php
    //获取今日开始时间戳和结束时间戳  
    $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));  
    $endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;  
    //获取昨日起始时间戳和结束时间戳  
    $beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));  
    $endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;  
    //获取本周起始时间戳和结束时间戳   
    $beginThisweek = mktime(0,0,0,date('m'),date('d')-date('w')+1,date('y'));  
    $endThisweek=time();  
    //获取上周起始时间戳和结束时间戳  
    $beginLastweek=mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));  
    $endLastweek=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));  
    //获取本月起始时间戳和结束时间戳  
    $beginThismonth=mktime(0,0,0,date('m'),1,date('Y'));  
    $endThismonth=mktime(23,59,59,date('m'),date('t'),date('Y'));  
     //上个月的起始时间:  
    $begin_time = strtotime(date('Y-m-01 00:00:00',strtotime('-1 month')));  
    $end_time = strtotime(date("Y-m-d 23:59:59", strtotime(-date('d').'day')));  
    $begin_year = strtotime(date("Y",time())."-1"."-1"); //本年开始  
    $end_year = strtotime(date("Y",time())."-12"."-31"); //本年结束  
    //现在的时间到第二天凌晨相差的时间戳  
    $time = (strtotime(date('Y-m-d'))+3600*24) - time() ;

日期格式

<?php
    echo '<br>上周起始时间:<br>';
        echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1-7,date("Y"))),"\n";
        echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7-7,date("Y"))),"\n";
        echo '<br>本周起始时间:<br>';
        echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y"))),"\n";
        echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y"))),"\n";
        echo '<br>上月起始时间:<br>';
        echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y"))),"\n";
        echo date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y"))),"\n";
        echo '<br>本月起始时间:<br>';
        echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y"))),"\n";
        echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y"))),"\n";
        //本年起始
        echo date('Y-01-01'); 
        //结束日期 
        echo date('Y-12-31');

获取本周所有日期

<?php
    /**
     * 获取本周所有日期
     */
    function get_week($time = '', $format='Y-m-d'){
      $time = $time != '' ? $time : time();
      //获取当前周几
      $week = date('w', $time);
      $date = [];
      for ($i=1; $i<=7; $i++){
        $date[$i] = date($format ,strtotime( '+' . $i-$week .' days', $time));
      }
      return $date;
    }

获取最近七天日期

<?php
    /**
     * 获取最近七天所有日期
     */
    function get_weeks($time = '', $format='Y-m-d'){
      $time = $time != '' ? $time : time();
      //组合数据
      $date = [];
      for ($i=1; $i<=7; $i++){
        $date[$i] = date($format ,strtotime( '+' . $i-7 .' days', $time));
      }
      return $date;

公司使用的软件供应商的软件只开发了备份功能,没有覆盖和定时删除,磁盘经常会占满,需要手动删除,便有了这个需求。

@echo off 
forfiles /p D:\test /m A*.zip /d -6 /c "cmd /c del @path"

A*.zip 开头为A的.zip文件

-6 6天前文件

在Linux系统中,可以使用du(disk usage)命令来查看文件夹下特定文件的总大小。

如果想要查看以"GPS"开头的文件的总大小,可以结合使用find命令和du命令。

以下是一个示例命令:

find . -type f -name 'GPS*' -exec du -ch {} +

这个命令的解释如下:

find .:在当前目录下查找文件。

-type f:只查找文件,不包括目录。

-name 'GPS*':查找文件名以"GPS"开头的文件。

`-exec du -ch {}
+:对找到的每个文件执行du命令,-c表示显示总计,-h表示以易读的格式(如KB、MB、GB)显示大小,{}是一个占位符,代表find命令找到的每个文件名,+表示将所有找到的文件名作为参数一次性传递给du`命令。

执行这个命令后,将看到以"GPS"开头的所有文件的总大小。

如果文件数量非常多,使用 find 命令结合 -exec 选项可能会导致性能问题,因为 -exec 会为每个匹配的文件调用一次 du 命令。对于几十万个文件,这可能会导致大量的进程创建和销毁,从而影响性能。

在这种情况下,可以使用以下命令来优化性能:

find . -type f -name 'GPS*' -print0 | xargs -0 du -ch | grep 'total$'

这个命令的解释如下:

  • find . -type f -name 'GPS*' -print0-print0
    选项会将找到的文件名输出为以 null 字符(\0)分隔的字符串,这对于包含空格和特殊字符的文件名是安全的。
  • |
    管道符,将前一个命令的输出作为后一个命令的输入。
  • xargs -0 du -chxargs -0
    会读取来自 find 的输入,并将 null 字符分隔的字符串作为参数传递给 du 命令。这样可以避免因为文件名中的特殊字符而导致的问题。
  • | grep 'total$'grep

命令用于过滤输出,只显示包含 "total" 的行,即 du 命令的总计行。

这个命令会一次性处理所有找到的文件,而不是为每个文件创建一个新的 du 进程,从而提高了效率。此外,使用 xargs 可以有效地处理大量的文件,因为它会根据系统内存和 du 命令的参数限制来决定一次传递多少个文件名给 du 命令。

在MySQL中,有时候我们需要批量替换数据库中某个字段的内容,通常情况下我们需要一个一个进行替换。然而,现在我们可以使用以下代码来实现批量替换的功能,从而节省时间和精力。

单个词语批量

UPDATE 表名 SET 字段名 = REPLACE(字段名, '被替换','替换成');

这个代码的作用是在指定的表和字段中,将包含"被替换"的记录进行批量替换。使用"REPLACE"函数可以快速将指定内容替换为新的内容。

多个词语批量

UPDATE 表名 SET 字段名 = REPLACE(REPLACE(字段名, '被替换1','替换成1'),'被替换2','替换成2')