From dc11b07c4eb2cf114bdd218a9f16f8993337e0db Mon Sep 17 00:00:00 2001 From: miteruzo Date: Thu, 29 Jun 2023 23:16:09 +0900 Subject: [PATCH] =?UTF-8?q?DB=20=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2023_06_29_220600_create_chats_table.sql | 27 +++++++++++++ .../2023_06_29_224300_create_users_table.sql | 22 ++++++++++ server/modules/chat.mod.php | 40 +++++++++++++++++++ server/modules/common.mod.php | 21 ---------- 4 files changed, 89 insertions(+), 21 deletions(-) create mode 100644 server/migrations/2023_06_29_220600_create_chats_table.sql create mode 100644 server/migrations/2023_06_29_224300_create_users_table.sql create mode 100644 server/modules/chat.mod.php delete mode 100644 server/modules/common.mod.php diff --git a/server/migrations/2023_06_29_220600_create_chats_table.sql b/server/migrations/2023_06_29_220600_create_chats_table.sql new file mode 100644 index 0000000..b53e97d --- /dev/null +++ b/server/migrations/2023_06_29_220600_create_chats_table.sql @@ -0,0 +1,27 @@ +CREATE TABLE + IF NOT EXISTS +goatoh_training.chats +( + id + INT + NOT NULL + AUTO_INCREMENT + COMMENT '主キー', + + user_id + INT + NOT NULL + COMMENT 'ユーザのキー', + + text + TEXT + CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci + NOT NULL + COMMENT 'チャット・テキスト', + + PRIMARY KEY (id) +) +ENGINE = InnoDB +CHARSET = utf8mb4 COLLATE utf8mb4_general_ci +COMMENT = 'チャット'; + diff --git a/server/migrations/2023_06_29_224300_create_users_table.sql b/server/migrations/2023_06_29_224300_create_users_table.sql new file mode 100644 index 0000000..4b7c27d --- /dev/null +++ b/server/migrations/2023_06_29_224300_create_users_table.sql @@ -0,0 +1,22 @@ +CREATE TABLE + IF NOT EXISTS +goatoh_training.users +( + id + INT + NOT NULL + AUTO_INCREMENT + COMMENT '主キー', + + name + VARCHAR(30) + CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci + NOT NULL + COMMENT 'ユーザ名', + + PRIMARY KEY (id) +) +ENGINE = InnoDB +CHARSET = utf8mb4 COLLATE utf8mb4_general_ci +COMMENT = 'ユーザ'; + diff --git a/server/modules/chat.mod.php b/server/modules/chat.mod.php new file mode 100644 index 0000000..b1ff0ba --- /dev/null +++ b/server/modules/chat.mod.php @@ -0,0 +1,40 @@ + db = new mysqli ($db_host, $db_user, $db_pass, 'goatoh_training', + $db_port); + } + + function + sendChat ( + int $user_id, + string $text): + void + { + $sql = " + INSERT INTO + chats ( + id, + text) + VALUES + ( + $user_id, + '$text')"; + $this -> db -> query ($sql) or die ("db_insert error $sql"); + } +} + diff --git a/server/modules/common.mod.php b/server/modules/common.mod.php deleted file mode 100644 index 8aafd26..0000000 --- a/server/modules/common.mod.php +++ /dev/null @@ -1,21 +0,0 @@ - db = new mysqli ($db_host, $db_user, $db_pass, 'goatoh_training', $db_port); - } -} -