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);
}
}