webman:通过orm访问数据库

一,文档地址:

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

二,安装所需的库

$ composer require -W illuminate/database illuminate/pagination illuminate/events symfony/var-dumper laravel/serializable-closure

三,配置文件:

config/database.php

return [
    // 默认数据库
    'default' => 'mysql',

    // 各种数据库配置
    'connections' => [
        'mysql' => [
            'driver'      => 'mysql',
            'host'        => '127.0.0.1',
            'port'        => 3306,
            'database'    => 'test',
            'username'    => 'root',
            'password'    => '',
            'unix_socket' => '',
            'charset'     => 'utf8',
            'collation'   => 'utf8_unicode_ci',
            'prefix'      => '',
            'strict'      => true,
            'engine'      => null,
            'options' => [
                \PDO::ATTR_TIMEOUT => 3
            ]
        ],
    ],
];

四,代码:

<?php

namespace app\controller;

use support\Request;
use support\Db;

class PinglunController
{
    public function index(Request $request)
    {
        //return response(__CLASS__);
                $data=['name' => 'webman'];


        $p = 1;
        $size=20;
        $offset = ($p-1)*$size;

        $pls = Db::table('pllist')
                ->orderBy('id', 'desc')
                ->offset($offset)
                ->limit($size)
                ->get();

        $data['pls']=$pls;
        var_dump($pls);

        return view('pinglun/index', $data);
    }

}

 

posted @   刘宏缔的架构森林  阅读(17)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
历史上的今天:
2021-12-21 linux(kubuntu 21.10): 配置五笔输入法
2021-12-21 linux(ubuntu 21.10):安装chrome
2021-12-21 linux(ubuntu 21.10): 安装phpmyadmin5.1.1 (php8.1.1)
2021-12-21 linux(ubuntu 21.10): apt-get安装mysql8.0.27
2021-12-21 ubuntu21.10:编译安装php8.1.1
2020-12-21 macos(big sur/11.1):安装python3(python 3.9.1)
点击右上角即可分享
微信分享提示