Browse Source

チャット

main
Miteruzo 1 year ago
parent
commit
8f615db95a
4 changed files with 41 additions and 45 deletions
  1. +12
    -4
      chat.php
  2. +18
    -0
      db_connection.php
  3. +6
    -21
      modules/chat.mod.php
  4. +5
    -20
      modules/user.mod.php

+ 12
- 4
chat.php View File

@@ -1,5 +1,8 @@
<?php <?php


require_once './db_connection.php';

require_once './modules/user.mod.php';
require_once './modules/chat.mod.php'; require_once './modules/chat.mod.php';




@@ -7,10 +10,15 @@ $user_id = $_GET['id'];
$pass = $_GET['pass']; $pass = $_GET['pass'];
$chat_message = $_GET['text']; $chat_message = $_GET['text'];


$user = User :: find ($user_id);

if ($user -> pass === $pass)
{
$chat = new Chat;


$chat -> user_id = $user_id;
$chat -> text = $chat_message;


$chat = new Chat;
$chat -> user_id = $user_id;
$chat -> text = $chat_message;
$chat -> insert ();
$chat -> insert ();
}



+ 18
- 0
db_connection.php View File

@@ -0,0 +1,18 @@
<?php

$config = include ('./config.php');

$db_host = $config['host'];
$db_port = $config['port'];
$db_user = $config['user'];
$db_pass = $config['pass'];

$__db_connection = new mysqli ($db_host, $db_user, $db_pass, 'goatoh_training',
$db_port);

unset ($config);
unset ($db_host);
unset ($db_port);
unset ($db_user);
unset ($db_pass);


+ 6
- 21
modules/chat.mod.php View File

@@ -3,29 +3,13 @@
class class
Chat Chat
{ {
private $db;

private $id;
var $user_id;
var $pass;

function
__construct ()
{
$config = include ('./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);
}
var $id;
var $user_id;
var $pass;


function function
insert (): insert ():
void
int
{ {
$sql = " $sql = "
INSERT INTO INSERT INTO
@@ -36,7 +20,8 @@ Chat
( (
{$this -> user_id}, {$this -> user_id},
'{$this -> text}')"; '{$this -> text}')";
$this -> db -> query ($sql) or die ("db_insert error $sql");
$GLOBALS['__db_connection'] -> query ($sql)
or die ("db_insert error $sql");
} }
} }



+ 5
- 20
modules/user.mod.php View File

@@ -3,25 +3,9 @@
class class
User User
{ {
private $db;

private $id;
var $name;
var $pass;

function
__construct ()
{
$config = include ('./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);
}
var $id;
var $name;
var $pass;


public static function public static function
find ( find (
@@ -35,7 +19,8 @@ User
user user
WHERE WHERE
id = $id"; id = $id";
$result = $this -> db -> query ($sql) or die ("db_select error $sql");
$result = $GLOBALS['__db_connection'] -> query ($sql)
or die ("db_select error $sql");


$row = $this -> db -> fetch_array ($result); $row = $this -> db -> fetch_array ($result);




Loading…
Cancel
Save