From 4c36377de9b168f9767c972527eeaeb5347fafb2 Mon Sep 17 00:00:00 2001 From: Miteruzo Date: Fri, 30 Jun 2023 20:06:50 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B5=E3=83=BC=E3=83=90=E7=94=A8=E3=83=AA?= =?UTF-8?q?=E3=83=9D=E3=82=B8=E3=83=88=E3=83=AA=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + chat.php | 12 ++++++ config.sample.php | 7 ++++ .../2023_06_29_220600_create_chats_table.sql | 27 +++++++++++++ .../2023_06_29_224300_create_users_table.sql | 22 ++++++++++ modules/chat.mod.php | 40 +++++++++++++++++++ 6 files changed, 110 insertions(+) create mode 100644 .gitignore create mode 100644 chat.php create mode 100644 config.sample.php create mode 100644 migrations/2023_06_29_220600_create_chats_table.sql create mode 100644 migrations/2023_06_29_224300_create_users_table.sql create mode 100644 modules/chat.mod.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..41c4035 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/config.php + diff --git a/chat.php b/chat.php new file mode 100644 index 0000000..2bc6225 --- /dev/null +++ b/chat.php @@ -0,0 +1,12 @@ + send_chat ($user_id, $chat_message); + diff --git a/config.sample.php b/config.sample.php new file mode 100644 index 0000000..ff96e3e --- /dev/null +++ b/config.sample.php @@ -0,0 +1,7 @@ + 'localhost', // MySQL のアドレス + 'port' => 3306, // MySQL のポート番号 + 'user' => 'root', // MySQL のユーザ名 + 'pass' => '']; // MySQL のパスワード + diff --git a/migrations/2023_06_29_220600_create_chats_table.sql b/migrations/2023_06_29_220600_create_chats_table.sql new file mode 100644 index 0000000..b53e97d --- /dev/null +++ b/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/migrations/2023_06_29_224300_create_users_table.sql b/migrations/2023_06_29_224300_create_users_table.sql new file mode 100644 index 0000000..4b7c27d --- /dev/null +++ b/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/modules/chat.mod.php b/modules/chat.mod.php new file mode 100644 index 0000000..2e95da4 --- /dev/null +++ b/modules/chat.mod.php @@ -0,0 +1,40 @@ + db = new mysqli ($db_host, $db_user, $db_pass, 'goatoh_training', + $db_port); + } + + function + send_chat ( + 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"); + } +} +