首页 > 数据库 >webman:用thinkorm访问数据库(v1.5.7)

webman:用thinkorm访问数据库(v1.5.7)

时间:2023-08-23 09:56:16浏览次数:52  
标签:webman 数据库 thinkorm orm v1.5 result composer think

一,官方文档地址:

https://www.workerman.net/doc/webman/db/thinkorm.html

二,安装组件

liuhongdi@lhdpc:/data/webman/imageadmin$ composer require -W webman/think-orm
./composer.json has been updated
Running composer update webman/think-orm --with-all-dependencies
Loading composer repositories with package information
Updating dependencies
Lock file operations: 4 installs, 0 updates, 0 removals
  - Locking psr/simple-cache (3.0.0)
  - Locking topthink/think-helper (v3.1.6)
  - Locking topthink/think-orm (v3.0.11)
  - Locking webman/think-orm (v1.1.1)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 4 installs, 0 updates, 0 removals
  - Downloading webman/think-orm (v1.1.1)
  - Installing psr/simple-cache (3.0.0): Extracting archive
  - Installing topthink/think-helper (v3.1.6): Extracting archive
  - Installing topthink/think-orm (v3.0.11): Extracting archive
  - Installing webman/think-orm (v1.1.1): Extracting archive
> support\Plugin::install
> support\Plugin::install
> support\Plugin::install
> support\Plugin::install
Generating autoload files
2 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found
Using version ^1.1 for webman/think-orm

三,配置数据库:

config/thinkorm.php

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 <?php   return [     'default' => 'mysql',     'connections' => [         'mysql' => [             // 数据库类型             'type' => 'mysql',             // 服务器地址             'hostname' => '127.0.0.1',             // 数据库名             'database' => 'yourbase',             // 数据库用户名             'username' => 'root',             // 数据库密码             'password' => 'yourpassword',             // 数据库连接端口             'hostport' => '3306',             // 数据库连接参数             'params' => [                 // 连接超时3秒                 \PDO::ATTR_TIMEOUT => 3,             ],             // 数据库编码默认采用utf8             'charset' => 'utf8mb4',             // 数据库表前缀             'prefix' => '',             // 断线重连             'break_reconnect' => true,             // 关闭SQL监听日志             'trigger_sql' => false,             // 自定义分页类             'bootstrap' =>  ''         ],     ], ];

四,访问数据库

1,model/Comment.php

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 <?php declare (strict_types = 1);   namespace app\model;   use think\Model; use think\facade\Db;   /**  * @mixin \think\Model  */ class Comment extends Model {     //类名与表名不一致时在这里指定数据表名     protected $table = "it_comment";       //page:当前页     //size: 每页的数量     public function list($path) {         $result = Db::table($this->table)->where('is_mod',1)->where('path',$path)->order(['cm_id'=>'desc'])->select();         return $result;     }       public function add($rowIns) {           $result = Db::name($this->table)->insertGetId($rowIns);           return $result;     } }

2,controller/ImageController.php

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 <?php namespace app\controller;   use support\Request; use app\result\Result;   use app\model\Comment as CommentModel;   class ImageController {     //图片的列表     public function list(Request $request)     {          $path = '_image_imageborder';          $comObj = new CommentModel();          $rows = $comObj->list($path);            return  Result::Success($rows);     } }

说明:刘宏缔的架构森林—专注it技术的博客,
网站:https://blog.imgtouch.com
原文: https://blog.imgtouch.com/index.php/2023/08/19/webman-yong-thinkorm-fang-wen-shu-ju-ku-v1-5-7/
代码: https://github.com/liuhongdi/ 或 https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: [email protected]

五,测试效果

六,查看webman的版本:

liuhongdi@lhdpc:/data/webman/imageadmin$ composer show workerman/webman-framework
name     : workerman/webman-framework
descrip. : High performance HTTP Service Framework.
keywords : High Performance, http service
versions : * v1.5.7
...

标签:webman,数据库,thinkorm,orm,v1.5,result,composer,think
From: https://www.cnblogs.com/architectforest/p/17650323.html

相关文章

  • webman:用thinkcache访问redis(v1.5.7)
    一,官方文档地址:https://www.workerman.net/doc/webman/db/thinkcache.html二,安装组件liuhongdi@lhdpc:/data/webman/imageadmin$composerrequire-Wwebman/think-cache三,配置redisconfig/thinkcache.php,按自己的实际情况配置12345678910111213......
  • webman:配置异常处理返回json格式(v1.5.7)
    一,添加一个除0错的异常代码:页面显示效果如图:二,配置:php代码1,config/123456789101112131415161718<?php/** *Thisfileispartofwebman. * *LicensedunderTheMITLicense *Forfullcopyrightandlicenseinformation......
  • webman:安装/创建项目(v1.5.7)
    一,官方文档:1,官方站:https://www.workerman.net/webman2,安装文档:https://www.workerman.net/doc/webman/install.html二,准备安装环境:1,需求环境需求PHP>=7.2Composer >=2.02,查看本地环境:php:liuhongdi@lhdpc:~$/usr/local/soft/php8/bin/php--version......
  • webman:修改默认页面(v1.5.7)
    一,默认页面的内容:说明:代码位于app/IndexController.php参考这个文档:https://www.workerman.net/doc/webman/route.html原始代码:显示了README.md这个文件的内容12345678910classIndexController{    publicfunctionindex(Request$reques......
  • webman:管理命令(v1.5.7)
     一,启动和停止1,启动#-d:以daemon方式启动,用于生产环境liuhongdi@lhdpc:/data/webman/imageadmin$phpstart.phpstart-dWorkerman[start.php]startinDAEMONmode-------------------------------------------WORKERMAN--------------------------------------......
  • webman:配置路由(v1.5.7)
     一,官方文档地址:https://www.workerman.net/doc/webman/route.html二,php代码:config/route.php1234567891011121314151617181920<?php useWebman\Route; //指定默认页面Route::get('/',[app\controller\IndexController::class......
  • webman:返回统一格式的json(v1.5.7)
     一,php代码:1,类代码:app/result/Result.php1234567891011121314151617181920212223242526272829303132333435<?php/*   统一格式的返回json数据*/namespaceapp\result; classResult{    //success:code......
  • 【博客重构之路】webman-admin安装指南
    原文地址【博客重构之路】webman-admin安装指南视频地址【bilibili】webman是什么webman是一款基于workerman开发的高性能HTTP服务框架。webman用于替代传统的php-fpm架构,提供超高性能可扩展的HTTP服务。你可以用webman开发网站,也可以开发HTTP接口或者微服务。除此之外,webma......
  • IoTOS-v1.5.3 新增 智能诊断&会话记录导出
    IoTOS v1.5.3     一、新增智能诊断       智能诊断功能:    智能诊断会根据不同上游接口能力开放提供接近官方甚至比官方更加完善的智能诊断功能。    目前还原OneLink官方智能诊断功能包括动效、诊断建议等可供诊断的接口基本全部覆盖;(卡状态、......
  • SREWorks v1.5 版本发布 | 基于实时作业平台的日志聚类开源
    在经过v1.0\~v1.4四个版本迭代后,SREWorks的核心底座已经表现出极高的稳定性和成熟性。在v1.5版本中,SREWorks开发团队在核心底座上,进行了较多的数智化能力迭代。同时,在数智能力迭代过程中,我们也维持着与SREWorks用户较高的沟通频率。我们发现大家普遍对于监控数据之上的数智化能力比......