emailSql.php 1.7 KB
<?php

namespace Model;

/**
 * @author:dc
 * @time 2023/2/13 14:11
 * Class email
 */
class emailSql {

    public static $table = 'emails';


    /**
     * 通过email查询
     * @param $email
     * @return string
     * @author:dc
     * @time 2023/2/13 14:50
     */
    public static function first($email, $filed='*'):string {
        return "select {$filed} from `".static::$table."` where `".(is_numeric($email) ? 'id' : 'email')."` = '{$email}' limit 1";
    }


    /**
     * @param $token
     * @return array
     * @author:dc
     * @time 2023/2/17 14:21
     */
    public static function firstByToken($token):array {
        return [
            "select * from `".static::$table."` where `token` = ? limit 1",
            [
                $token
            ]
        ];
    }

    /**
     * 统计邮箱的数量
     * @return string
     * @author:dc
     * @time 2023/2/14 16:16
     */
    public static function count():string {
        return "select count(*) from `".static::$table."` limit 1";
    }


    /**
     * 邮箱是否存在的sql
     * @param string $email
     * @return array
     * @author:dc
     * @time 2023/2/17 10:15
     */
    public static function hasEmail(string $email):array {
        return [
            "select `id` from `".static::$table."` where `email` = ? limit 1",
            [
                $email
            ]
        ];
    }

    /**
     * 获取字段值
     * @param $where
     * @param string $field
     * @return string
     * @author:dc
     * @time 2023/3/10 10:46
     */
    public static function getValues($where,$field='id'){
        return "select `{$field}` from `".static::$table."` where ".dbWhere($where);
    }




}