use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;

class Xlsx
{
    public static function load($filePath)
    {
        $inputFileType = IOFactory::identify($filePath);
        $excelReader = IOFactory::createReader($inputFileType);
        $PHPExcel = $excelReader->load($filePath);
        return $PHPExcel;
    }

    /**
     * 迭代每一行
     * @param  string   $filePath
     * @param  callable $callback         参数 $rowData 行数据, $rowKey行号2开始
     */
    public static function iterator(
        $filePath,
        callable $callback,
        $hasHeader = true,
        $sheetIndex = 0,
        $onlyExistingCell = true,
        $startColumn = null,
        $endColumn = null
    ) {
        $excel = static::load($filePath);
        $sheet = $excel->getSheet($sheetIndex);
        $rows = $sheet->getRowIterator();
        $header = [];

        foreach ($rows as $rowKey => $row) {
            $rowData = [];

            $cellIterator = $row->getCellIterator();

            // 程序自己判断存在的cell可能不准
            if ($onlyExistingCell === true) {
                $cellIterator->setIterateOnlyExistingCells($onlyExistingCell);
            } else {
                $cellIterator->resetStart($startColumn);
                $cellIterator->resetEnd($endColumn);
            }

            foreach ($cellIterator as $colKey => $cell) {
                if ($hasHeader) {
                    if ($rowKey == 1) {
                        $header[$colKey] = trim($cell->getValue());
                    } else {
                        if (!array_key_exists($colKey, $header)) {
                            continue;
                        }
                        $rowData[$header[$colKey]] = $cell->getValue();
                    }
                }
            }
            if ($rowKey > 1) {
                $res = $callback($rowData, $rowKey);
                if ($res === false) {
                    return;
                }
            }
        }
    }
}

FROM php:7.2.2-fpm

# 国内源
RUN apt-get clean
RUN apt-get update
  
RUN apt-get install -y libpq-dev
RUN docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql
RUN docker-php-ext-install pdo
RUN docker-php-ext-install pdo_pgsql

json展开值

SELECT "value" FROM "inner_id_mapping", json_each_text(inner_id_mapping.ids::json) limit 100

窗口函数

增加idx的序号字段,使用over进行分窗,后续可通过idx获取组内的行数

SELECT *, row_number() over(partition by province order by product_num desc) idx 
FROM (
    SELECT sum(product_num) as product_num, "province", "channel" 
    FROM "inner_analyse" 
    GROUP BY "channel", "province"
) "b"
mysql:show databases
pgsql:\l 或者\l+(显示的信息要多一些)

mysql:use xx
pgsql:\c xx

mysql:show tables
pgsql:\dt

退出pg控制台

\q

复制后无法启动

http://www.viiis.cn/news/show_100077.html

chown -R postgres:postgres /data/
systemctl start postgresql-12 

pgsql都要带版本号

创建用户

CREATE USER testuser PASSWORD 'testuser';

创建数据库

CREATE DATABASE dba;

apache 删除响应header

Header unset Access-Control-Allow-Origin

apache 增加header

Header set Access-Control-Allow-Methods *  

nginx 增加header

add_header Access-Control-Allow-Origin $http_origin always;

server {
    listen 80;
    server_name geo.datav.aliyun.com;
    location / {
        proxy_pass http://geo.datav.aliyun.com;
    }
}

  • 冷备份
    直接备份存储mongo数据的文件夹
  • 去除认证
  • 找到mongo配置默认/etc/mongod.conf
  • 注释其中其中

    security:
    authorization: enabled
  • 停止原有的mongo
  • 进入mongo执行目录,指定dbpath启动mongo

    ./mongod --logpath "/data/bak/log/mongodb/mongodb.log" --logappend --dbpath "/data/bak/mongodb"
  • 连接mongo不需要密码

    ./mongo 
  • 热备份

    mongodump -d db_shzhijian -o /data/bak

    将数据备份到指定目录

  • 恢复数据

    ./mongorestore -d db_shzhijian /data/bak/db_shzhijian
  • 开启认证重启mongo
  • php 未认证
  • php最好用3.6版本
  • authSource指的是当前用户的认证源,也就是他存在哪个库里面,root账户存在的是admin库,跟mysql不同