惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
Last Week in AI
Last Week in AI
博客园_首页
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
大猫的无限游戏
大猫的无限游戏
人人都是产品经理
人人都是产品经理
V
Visual Studio Blog
宝玉的分享
宝玉的分享
博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
T
Tailwind CSS Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
量子位
博客园 - 聂微东
S
SegmentFault 最新的问题
博客园 - 司徒正美
罗磊的独立博客
V
V2EX
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
美团技术团队
小众软件
小众软件
Jina AI
Jina AI

博客园 - tying

fastadmin mongodb 处理及使用 mysql的知识扩展 <论语> fastadmin配合宝塔面板造成cors error 跨域问题 一个小并发,引起的数据错误 小型在线聊天功能 技术文章分享 shopxo学习过程 fastadmin 開發好文章 fastadmin常用前端组件 2024-11-13关于监管特殊停牌炒作股票事件--兼此事件复盘 深入浅出的讲解mysql优化 关于gruop by,where和order by ,以及一些mysql的探讨 fastadmin使用感受 fastadmin命令行模式--command mac 下Fastadmin 框架搭建 Mac电脑php环境搭建 关于php+mysql性能在实际工作中的应用实例 yii2的单元测试 d8的入口文件及引申
fastadmin数据库操作
tying · 2025-07-14 · via 博客园 - tying

1.model操作

如题,使用命令行工具生成数据库表对应的model,通过model进行数据库操作,操作方式有些像yii2框架

例如

//插入或者更新

$user =  new Users();

$user->username = 'zhangsan';

$user->password = md5("123456"+$salt);

$user->save();

//查询

$users = Users::where(['status'=>0])->find();//拿一条

$users = Users::where(['status'=>0])->select();//拿多条

$users = Users::where(['status'=>0])->select();//拿多条

$users = Users::where(['status'=>0])->paginate($limit,['page'=>$page]);//分页

2.db 原生sql查询

use think\Db;

Db::query("select * from user where id = :id",[“:id”=$id]);//查询

Db::execute("update user set username = :username where id = :id",[':username'=>$username,':id'=>$id]);//非查询sql

3.db的函数方法

 * @method static Query name(string $name) 指定数据表(不含前缀)

 * @method static Query where(mixed $field, string $op = null, mixed $condition = null) 查询条件

 * @method static Query join(mixed $join, mixed $condition = null, string $type = 'INNER') JOIN查询

 * @method static Query union(mixed $union, boolean $all = false) UNION查询

 * @method static Query limit(mixed $offset, integer $length = null) 查询LIMIT

 * @method static Query order(mixed $field, string $order = null) 查询ORDER

 * @method static Query cache(mixed $key = null , integer $expire = null) 设置查询缓存

 * @method static mixed value(string $field) 获取某个字段的值

 * @method static array column(string $field, string $key = '') 获取某个列的值

 * @method static Query view(mixed $join, mixed $field = null, mixed $on = null, string $type = 'INNER') 视图查询

 * @method static mixed find(mixed $data = null) 查询单个记录

 * @method static mixed select(mixed $data = null) 查询多个记录

 * @method static integer insert(array $data, boolean $replace = false, boolean $getLastInsID = false, string $sequence = null) 插入一条记录

 * @method static integer insertGetId(array $data, boolean $replace = false, string $sequence = null) 插入一条记录并返回自增ID

 * @method static integer insertAll(array $dataSet) 插入多条记录

 * @method static integer update(array $data) 更新记录

 * @method static integer delete(mixed $data = null) 删除记录

//例如

 $joinlist = Db("user")->where('jointime', 'between time', [$starttime, $endtime])

            ->field('jointime, status, COUNT(*) AS nums, DATE_FORMAT(FROM_UNIXTIME(jointime), "%Y-%m-%d") AS join_date')

            ->group('join_date')

            ->select();