一、模块设计
二、技术选型
IDE:phpstorm
mysql:5.1
php:7.3.29
运行工具:phpstudy
三、数据库设计
用户表:
CREATE TABLE `t_user` (`id` int(11) NOT NULL AUTO_INCREMENT,`uname` varchar(255) DEFAULT NULL,`upass` varchar(255) DEFAULT NULL,PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8
图书表:
CREATE TABLE `t_book` (`id` bigint(20) NOT NULL AUTO_INCREMENT,`bookname` varchar(512) NOT NULL,`author` varchar(512) NOT NULL,`publish` varchar(512) NOT NULL,`isbn` varchar(512) NOT NULL,`introduction` varchar(512) NOT NULL,`language` varchar(128) NOT NULL,`price` int(11) DEFAULT NULL,PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8
四、核心代码
DBConnection.php
<?phpclass DbConnection
{public static function getConnection(): mysqli{$connection = mysqli_connect('127.0.0.1','root','root','bookmanagesys','3306'); //创建数据库连接if(!$connection){ //如果失败die('连接mysql数据库失败'.mysqli_error()); //显示出错误信息}mysqli_select_db( $connection, "bookmanagesys");mysqli_set_charset($connection, "utf8");return $connection;}}
BookController.php
<?php
include '../bean/User.php';
include '../dao/BookDao.php';header("Content-Type: application/json;charset=UTF-8");// 从请求中获取原始数据
$json = file_get_contents('php://input');// 将其转换为 PHP 对象
$param = json_decode($json);$method = $param->method;$bookDao = new BookDao();
$res = new Res();switch ($method){case 'queryAll'://查询全部$res->setData($bookDao->queryAll($param));$res->setSuccess(true);break;case 'save'://保存$res->setData($bookDao->save($param));$res->setSuccess(true);break;case 'update'://更新$res->setData($bookDao->update($param));$res->setSuccess(true);break;case 'delete'://删除$res->setData($bookDao->delete($param));$res->setSuccess(true);break;
}echo json_encode($res);?>
五、页面设计
1. 登陆页面
2. 主页面
3. 新增图书
4. 修改图书