@@ -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 = 'チャット'; | |||||
@@ -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 = 'ユーザ'; | |||||
@@ -0,0 +1,40 @@ | |||||
<?php | |||||
class | |||||
Chat | |||||
{ | |||||
var $db; | |||||
function | |||||
__construct () | |||||
{ | |||||
$config = include (__DIR__ . '/config.php'); | |||||
$db_host = $config['host']; | |||||
$db_port = $config['port']; | |||||
$db_user = $config['user']; | |||||
$db_pass = $config['pass']; | |||||
$this -> 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"); | |||||
} | |||||
} | |||||
@@ -1,21 +0,0 @@ | |||||
<?php | |||||
class | |||||
Common | |||||
{ | |||||
var $db; | |||||
function | |||||
__construct () | |||||
{ | |||||
$config = include (__DIR__ . '/config.php'); | |||||
$db_host = $config['host']; | |||||
$db_port = $config['port']; | |||||
$db_user = $config['user']; | |||||
$db_pass = $config['pass']; | |||||
$this -> db = new mysqli ($db_host, $db_user, $db_pass, 'goatoh_training', $db_port); | |||||
} | |||||
} | |||||