config配置

<?php
/**
* User: Eden
* Date: 2019/3/30
* 共有内容
*/

/**
 CREATE TABLE `tf_configs` (
    `id` int(11) NOT NULL COMMENT 'id',
    `key` varchar(100) NOT NULL COMMENT 'key',
    `value` text NOT NULL COMMENT 'value',
    `create_time` int(11) NOT NULL COMMENT '创建时间'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='配置表';

 */
namespace CommonService;
class ConfigService extends CommonService {
    /**
     * 查询单个key
     * $key = 'total_donate';
     * @param $key
     * @return array
     */
    public function queryOneKey($key) {
        $configs = M('configs');
        $data = $configs->where(['key'=>$key])->find();
        return $data['value'];
    }

    /**
     * 查询多个key
     * $keys = 'total_donate,total_help,total_join';
     * $keys = ['total_donate','total_help','total_join'];
     * @param array $keys
     * @return mixed
     */
    public function queryKeys($keys = [])
    {
        $where = [];
        if ($keys) {
            $where['key'] = ['in', $keys];
        }
        $configs = M('configs');
        $data = $configs->where($where)->getField('`key`, `value`');
        return $data;
    }

    /**
     * 查询key
     * $key = ['key'=>['in', 'total_donate,total_help,total_join']];
     * $key = ['key'=>['in', ['total_donate','total_help','total_join']]];
     * @param $key
     * @return array
     */
    public function queryKey($key) {
        $configs = M('configs');
        $website = $configs->where($key)->getField('`key`, `value`');
        return $website;
    }

}

这种配置表,比较灵活,属于竖表。比传统的横表更加的灵活。使用的时候也有区别,需要额外处理。

原文地址:https://www.cnblogs.com/jiqing9006/p/10625363.html