From 69194b550a3f9b04cee75635c4d875f8adad37bc Mon Sep 17 00:00:00 2001 From: miteruzo Date: Sat, 1 Jul 2023 08:28:52 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=A6=E3=83=BC=E3=82=B6=E3=81=AE=E3=83=91?= =?UTF-8?q?=E3=82=B9=E3=83=AF=E3=83=BC=E3=83=89=E8=AA=8D=E8=A8=BC=E3=81=AE?= =?UTF-8?q?=E3=81=9F=E3=82=81=E3=81=AE=20DB=20=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chat.php | 12 +++-- ...3_07_01_080700_add_pass_to_chats_table.sql | 1 + modules/chat.mod.php | 12 +++-- modules/user.mod.php | 50 +++++++++++++++++++ 4 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 migrations/2023_07_01_080700_add_pass_to_chats_table.sql create mode 100644 modules/user.mod.php diff --git a/chat.php b/chat.php index 135d717..faac59e 100644 --- a/chat.php +++ b/chat.php @@ -1,14 +1,16 @@ send ($user_id, $chat_message); + + +$chat = new Chat; +$chat -> user_id = $user_id; +$chat -> text = $chat_message; +$chat -> insert (); diff --git a/migrations/2023_07_01_080700_add_pass_to_chats_table.sql b/migrations/2023_07_01_080700_add_pass_to_chats_table.sql new file mode 100644 index 0000000..f0272f4 --- /dev/null +++ b/migrations/2023_07_01_080700_add_pass_to_chats_table.sql @@ -0,0 +1 @@ +ALTER TABLE `users` ADD `pass` VARCHAR(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'パスワード' AFTER `name`; diff --git a/modules/chat.mod.php b/modules/chat.mod.php index 5318026..c478338 100644 --- a/modules/chat.mod.php +++ b/modules/chat.mod.php @@ -5,6 +5,10 @@ Chat { private $db; + private $id; + var $user_id; + var $pass; + function __construct () { @@ -20,9 +24,7 @@ Chat } function - send ( - int $user_id, - string $text): + insert (): void { $sql = " @@ -32,8 +34,8 @@ Chat text) VALUES ( - $user_id, - '$text')"; + {$this -> user_id}, + '{$this -> text}')"; $this -> db -> query ($sql) or die ("db_insert error $sql"); } } diff --git a/modules/user.mod.php b/modules/user.mod.php new file mode 100644 index 0000000..ca998f0 --- /dev/null +++ b/modules/user.mod.php @@ -0,0 +1,50 @@ + db = new mysqli ($db_host, $db_user, $db_pass, 'goatoh_training', + $db_port); + } + + public static function + find ( + int $id): + Self + { + $sql = " + SELECT + * + FROM + user + WHERE + id = $id"; + $result = $this -> db -> query ($sql) or die ("db_select error $sql"); + + $row = $this -> db -> fetch_array ($result); + + $self = new Self; + $self -> id = $id; + $self -> name = $row['name']; + $self -> pass = $row['pass']; + + return $self; + } +} +