easyswoole数据库连接池_easyswoole快速实现一个网站的api接口程序

本教程详细介绍了如何利用Easyswoole框架快速实现一个网站的API接口,包括安装组件、设计数据库表、配置数据库连接池、自动生成CRUD控制器和模型。通过示例展示了创建会员、文章分类、文章、评论和置顶等表的DDL,并演示了如何注册数据库连接池和初始化基础控制器。最后,强调了接口完善和权限控制的后续工作。
摘要由CSDN通过智能技术生成

目前,easyswoole已经成为了最知名的swoole框架之一,本人也用easyswoole开发过很多个项目了,现在就来讲一讲如何用easyswoole快速实现一个网站的curd功能的接口。

安装easyswoole和相关组件

环境方面本人不多做说明,可以去官方文档查看。

新增composer.json文件{

"require": {

"easyswoole/easyswoole": "^3.2",

"easyswoole/mysqli": "^1.2",

"tioncico/curd-automatic-generation": "^1.0"

},

"autoload": {

"psr-4": {

"App\\": "Application/"

}

}

}

然后输入以下命令进行引入,安装组件库:composer up

mkdir -p Application/HttpController

php ./vendor/easyswoole/easyswoole/bin/easyswoole install

设计数据表

假设我们需要做一个简单的文章管理系统,需要用户,文章,评论,置顶,分类,这5个表:

新增文件 test.php<?php

/**

* Created by PhpStorm.

* User: tioncico

* Date: 19-7-27

* Time: 上午11:40

*/

include "./vendor/autoload.php";

//会员列表

$result = \EasySwoole\Mysqli\DDLBuilder\DDLBuilder::table('user_list', function (\EasySwoole\Mysqli\DDLBuilder\Blueprints\TableBlueprint $blueprint) {

$blueprint->colInt('id', '11')->setColumnComment('主键id')->setIsPrimaryKey()->setIsAutoIncrement();

$blueprint->colVarChar('userAccount', '32')->setColumnComment('会员账号');

$blueprint->colVarChar('userName', '32')->setColumnComment('会员昵称');

$blueprint->colVarChar('userPassword', '32')->setColumnComment('会员密码');

$blueprint->colDateTime('addTime')->setColumnComment('新增时间');

$blueprint->colTinyInt('isAdmin', 1)->setColumnComment('是否会管理员')->setDefaultValue(0);

$blueprint->setTableComment('会员列表');

$blueprint->setTableEngine(\EasySwoole\Mysqli\DDLBuilder\Enum\Engines::INNODB);

$blueprint->setTableCharset(\EasySwoole\Mysqli\DDLBuilder\Enum\Character::UTF8_GENERAL_CI);

$blueprint->indexNormal('userAccount', ['userAccount']);

});

echo $result;

//文章分类列表

$result = \EasySwoole\Mysqli\DDLBuilder\DDLBuilder::table('article_list', function (\EasySwoole\Mysqli\DDLBuilder\Blueprints\TableBlueprint $blueprint) {

$blueprint->colInt('id', '11')->setColumnComment('主键id')->setIsPrimaryKey()->setIsAutoIncrement();

$blueprint->colInt('pid', 11)->setColumnComment('上级id');

$blueprint->colVarChar('categoryName', '64')->setColumnComment('分类名称');

$blueprint->setTableComment('分类列表');

$blueprint->setTableEngine(\EasySwoole\Mysqli\DDLBuilder\Enum\Engines::INNODB);

$blueprint->setTableCharset(\EasySwoole\Mysqli\DDLBuilder\Enum\Character::UTF8_GENERAL_CI);

});

echo $result;

//文章列表

$result = \EasySwoole\Mysqli\DDLBuilder\DDLBuilder::table('article_list', function (\EasySwoole\Mysqli\DDLBuilder\Blueprints\TableBlueprint $blueprint) {

$blueprint->colInt('id', '11')->setColumnComment('

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值