LOADING

王思彤 发布的文章

import pymysql

# mysql链接初始化
# cursorclass 设置这个就可以key-value像php一样显示数据
def mysql_model():
    mysql_content = pymysql.connect(host="你的host", user="用户名",
                                    password="密码",
                                    database="数据库", charset="utf8", port=3306,
                                    cursorclass=pymysql.cursors.DictCursor)
    return mysql_content

首先需要引入依赖

import pymysql

# mysql链接初始化
# cursorclass
def mysql_model():
    mysql_content = pymysql.connect(host="你的host", user="用户名",
                                    password="密码",
                                    database="数据库", charset="utf8", port=3306,
                                    cursorclass=pymysql.cursors.DictCursor)
    return mysql_content


#但是一定要注意这种拼接方法只能拼接变量为字符串的,如果是不同类型的请往下看
def delAppMysqlStr():
    yesterday = "2020-01-08"
    del_app_sql = "delete from table where day = '" + yesterday + "'"
    mysql_content = mysql_model()
    # 创建一个游标
    cursor = mysql_content.cursor()
    cursor.execute(del_app_sql)
    mysql_content.commit()
    cursor.close()
    mysql_content.close()
    return 1
#如果是不同类型请使用参数绑定形式进行赋值
#切记占位符%s一定要和values数量匹配
def addAppMysqlStr():
    yesterday = "2020-01-08"
    add_sql = "insert into table (`day`,`union_id`,`appid`,`show_count`,`click_count`,`click_reg`,`cpm`,`money`,`third_app_id`,`platform`,`created_at`) value (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
    param = (yesterday, 1, 2, 3, 3.223, 2323,
             6.66, 11, 2, 123, "萨达所大")
    cursor.execute(add_sql, param)
    mysql_content.commit()
    cursor.close()
    mysql_content.close()
    return 1



当使用mysql like %gaga%类似这种索引时 假设索引为普通索引name 需要注意以下几种情况
sql语句为

//右侧百分号匹配 这种情况是可以用到索引的
select name,grade from job where name like "123%";

//双侧百分号匹配 这种情况是不可以用到索引的
select name,grade from job where name like "%123%";

因为本次取like时还需要取name 和 grade 以上这种情况应该设置多列索引 index_name_grade
这样的话索引就可以生效type为index

//多表关联查询
select job.name,job.grade from job left join user on job.level=user.level where job.name like "%123%";

这种情况如果想让索引生效需要把level也加在多列索引里

今天研究了下https环境配置 比我想象的简单许多 步骤如下
1首先去阿里云搜索ssl ca证书 一个账号可以免费申请20个 一个绑定一个域名 期限为1年
2然后按照点击验证 等候Symantec验证
3验证通过后点击下载QQ截图20191023002606.png

4下载后解压缩文件会得到pem和key 这两个需要放到你服务器上
QQ截图20191023002755.png

5接下来你需要如下配置nginx

server {
        listen 443 ssl default;
        server_name www.baidu.com;
        root /mnt/www/baidu/public;#你的项目入口
        ssl on;
        ssl_certificate /etc/ssl/www.baidu.pem;
        ssl_certificate_key /etc/ssl/www.baidu.key;

        keepalive_timeout   70;
   
        server_tokens off;
        fastcgi_param   HTTPS               on;
        fastcgi_param   HTTP_SCHEME         https;

        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    
        access_log  /var/log/nginx/baidu.log access;
        error_log  /var/log/nginx/err_baidu.log error;
        index index.php index.html;
        location / {
                try_files $uri $uri/ /index.php?$query_string;
        }
        location /app {
            add_header 'Access-Control-Allow-Origin' '*' 'always';
            alias /mnt/www/static_app/public/app-dev;
            try_files $uri $uri/ /index.php?$query_string;
        }

        location /pages/audition/ {
            add_header 'Access-Control-Allow-Origin' '*' 'always';
            try_files $uri $uri/ /pages/audition/;#需要指向下面的@router否则会出现vue的路由在nginx中刷新出>现404
            index  index.html index.htm;
        }

        location /pages/pages/ {
            add_header 'Access-Control-Allow-Origin' '*' 'always';
            try_files $uri $uri/ /pages/pages/;#需要指向下面的@router否则会出现vue的路由在nginx中刷新出现404
            index  index.html index.htm;
        }

        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass php-fpm;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
}

server {
        listen       80;
        server_name www.baidu.com;
        rewrite ^(.*) https://$host$1 permanent;
}

最后是监听80端口把http请求重写到https

brew tap tigerstrikemedia/homebrew-phalconphp
brew install php72-phalcon    (按照自己需要的版本 php7就是 php70-phalcon)
vim /Applications/MAMP/bin/php/php7.2.20/conf/php.ini
添加扩展
extension=/usr/local/Cellar/php72-phalcon/3.4.2/phalcon.so
重启MAMP
在phpinfo中发现phalcon 就说明安装成功

接下来安装phalcon 官方命令行工具
进入htdocs git clone https://github.com/phalcon/phalcon-devtools.git
获得phalcon-devtools文件夹
cd phalcon-devtools 复制phalcon 为phalcon.php
设置环境变量
ln -s /Applications/MAMP/htdocs/phalcon-devtools/phalcon.php /usr/local/bin/phalcon
设置权限

chmod +x /usr/local/bin/phalcon
重启终端
phalcon commands 查看是否安装成功

接下来是大坑 如果你用的是集成环境 并且没有把mac自带的php环境变量指向mamp中的时候就会报
ERROR: Phalcon extension isn't installed, follow these instructions to install it:
执行
brew link php@7.2
echo 'export PATH="/usr/local/opt/php@7.2/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/php@7.2/sbin:$PATH"' >> ~/.bash_profile
需要把如上两行写入 ~/.bash_profile文件 (如果没有就新建)
修改后执行source ~/.bash_profile  (如果不可以就先切换到~ 然后执行source bash_profile)
执行 php -v 和 which php检测是否成功
phalcon project demo --enable-webtools

public function collectionPage($datas,$filters){
        $datas_count = $datas->count();
        switch ($filters['sort_by']){
            case "DESC":
                $datas = $datas->sortByDesc($filters['sort'])->forPage($filters['page'],$filters['limit']);
                break;
            case "ASC":
                $datas = $datas->sortBy($filters['sort'])->forPage($filters['page'],$filters['limit']);
                break;
            default:
                $datas = $datas->sortBy($filters['sort'])->forPage($filters['page'],$filters['limit']);
                break;
        }
        $datas = $datas->values()->all();
        $option = [
            "path" => URL::full(),
            "pageName" => "page",
        ];
        return new LengthAwarePaginator($datas,$datas_count,$filters['limit'],$filters['page'],$option);
    }