PHP develops a simple book lending system to create a homepage database table

Create a table in the database that needs to be used for the main page, named yx_book

Set the following fields:

id: It is unique, type is int, and select the primary key .

name: Book name, type is varchar, length is 20.

price: Price, type decimal(4,2), used for data storage with relatively high precision.

The declaration syntax of decimal column is decimal(m,d).

1. M is the maximum number of numbers (precision). Its range is 1 to 65 (in older MySQL versions, the allowed range was 1 to 254).
        2. D is the number of digits to the right of the decimal point (scale). Its range is 0~30, but it must not exceed M.

uploadtime: storage time, type is datetime.

type: Book classification, type is varchar, length is 10.

total: The number of books, type is int, length is 50.

leave_number: The number of remaining books that can be borrowed, type is int, length is 10.

<?php
$SQL = " CREATE TABLE IF NOT EXISTS `yx_books` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `name` varchar(20) CHARACTER SET utf8 NOT NULL,
  `price` decimal(4,2) NOT NULL,
  `uploadtime` datetime NOT NULL,
  `type` varchar(10) CHARACTER SET utf8 NOT NULL,
  `total` int(50) DEFAULT NULL,
  `leave_number` int(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=42 ";
?>

Create another user borrowing table named lend

Set the following fields:

id: It is unique and the type is int. and select the primary key.

book_id: The id of each book, type is int

book_title: Type is varchar, length is 100.

lend_time: borrowing time, type is datetime.

user_id: user id, type is int

<?php
$SQL = " CREATE TABLE IF NOT EXISTS `lend` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `book_id` int(10) NOT NULL,
  `book_title` varchar(100) CHARACTER SET utf8 NOT NULL,
  `lend_time` datetime NOT NULL,
  `user_id` int(10) NOT NULL,
  PRIMARY KEY (`id`,`user_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=85 ";
?>

Of course you can also create it directly in phpMyAdmin.

Continuing Learning
||
<?php $SQL = " CREATE TABLE IF NOT EXISTS `yx_books` ( `id` int(10) NOT NULL AUTO_INCREMENT, `name` varchar(20) CHARACTER SET utf8 NOT NULL, `price` decimal(4,2) NOT NULL, `uploadtime` datetime NOT NULL, `type` varchar(10) CHARACTER SET utf8 NOT NULL, `total` int(50) DEFAULT NULL, `leave_number` int(10) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=42 "; ?>
submitReset Code