commit 4c36377de9b168f9767c972527eeaeb5347fafb2 Author: Miteruzo Date: Fri Jun 30 20:06:50 2023 +0900 サーバ用リポジトリ作成 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"); + } +} +