ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
### 创建模型 php bin/hyperf.php gen:model Users ### 配置数据库连接 .evn配置链接 APP_NAME=skeleton DB_DRIVER=mysql DB_HOST=localhost DB_PORT=3306 DB_DATABASE=swoole DB_USERNAME=swoole DB_PASSWORD=swoole DB_CHARSET=utf8mb4 DB_COLLATION=utf8mb4_unicode_ci DB_PREFIX= ### curd的练习操作 #### 查询单条 $users = User::query()->first(); #### 查询全部 $users = User::all(); #### 分页查询 $users = User::query()->paginate(2); #### 添加 $user = new User(); $user->username = 'abc' . mt_rand(1000, 9999); $user->create_at = time(); $user->update_at = time(); $res = $user->save(); #### 修改 $users = User::query()->find(1); $user->username = 'abc' . mt_rand(1000, 9999); #### 删除 $id = $this->request->input('id'); User::destroy($id);