Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
db_data/
10 changes: 10 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# If the requested file or directory does not exist,
# route the request to index.php with query parameters.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
</IfModule>
107 changes: 107 additions & 0 deletions data/0001_setup.sql

Large diffs are not rendered by default.

332 changes: 166 additions & 166 deletions db.php
Original file line number Diff line number Diff line change
@@ -1,167 +1,167 @@
<?php

class Database {
private $server;
private $username;
private $password;
private $database;
private $connection;

public function __construct($server, $username, $password, $database) {
$this->server = $server;
$this->username = $username;
$this->password = $password;
$this->database = $database;
}

public function connect() {
$this->connection = new PDO("mysql:host=$this->server;dbname=$this->database", $this->username, $this->password);
$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
public function execute($sql){
try {
$stmt = $this->connection->prepare( $sql);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_OBJ);
return $rows;
} catch (PDOException $e) {
echo "Query failed: " . $e->getMessage();
}
}
public function getChannelsLogged() {
try {
$stmt = $this->connection->prepare("SELECT DISTINCT(channel) FROM history");
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row) {
echo $row['channel'] . "<br>";
}
} catch (PDOException $e) {
echo "Query failed: " . $e->getMessage();
}
}

public function getHistory($channel) {
try {
$stmt = $this->connection->prepare("SELECT * FROM history WHERE channel = :channel");
$stmt->bindParam(':channel', $channel);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row) {
echo "ID: " . $row['id'] . ", chatmsg: " . $row['chatmsg'] . "<br>";
}
} catch (PDOException $e) {
echo "Query failed: " . $e->getMessage();
}
}
public function getCount($channel) {
try {
$stmt = $this->connection->prepare("SELECT count(*) FROM history WHERE channel = :channel");
$stmt->bindParam(':channel', $channel);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row) {
echo "ID: " . $row['id'] . ", chatmsg: " . $row['chatmsg'] . "<br>";
}
} catch (PDOException $e) {
echo "Query failed: " . $e->getMessage();
}
}
public function getEntryCount() {
try {
$stmt = $this->connection->prepare("SELECT count(*) as total FROM history");
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_OBJ);
return $rows;
} catch (PDOException $e) {
echo "Query failed: " . $e->getMessage();
}
}
public function addChannel($channel) {
try {
$stmt = $this->connection->prepare("INSERT INTO config (channel) VALUES (:channel)");
$stmt->bindParam(':channel', $channel);
$stmt->execute();
flog('ADDED CHANNEL '.$channel);
return "Channel added successfully.";
} catch (PDOException $e) {
flog("ADD CHANNEL FAIL ". $e->getMessage());
return "Query failed: " . $e->getMessage();
}
}
public function addJoin($username, $channel) {
try {
$stmt = $this->connection->prepare("INSERT INTO visits (username,channel) VALUES (:username, :channel)");
$stmt->bindParam(':username', $username);
$stmt->bindParam(':channel', $channel);
$stmt->execute();
flog('ADDED JOIN '.$channel);
return "Channel added successfully.";
} catch (PDOException $e) {
flog("ADD CHANNEL FAIL ". $e->getMessage());
return "Query failed: " . $e->getMessage();
}
}

public function addChat($author, $channel,$message,$emotes) {
try {
$stmt = $this->connection->prepare("INSERT INTO history (author, channel, message, emotes) VALUES (:author,:channel,:message,:emotes)");
$stmt->bindParam(':author', $author);
$stmt->bindParam(':channel', $channel);
$stmt->bindParam(':message', $message);
$stmt->bindParam(':emotes', $emotes);
$stmt->execute();
return "added successfully.";
} catch (PDOException $e) {
flog("ADD CHAT FAIL ". $e->getMessage());
return "Query failed: " . $e->getMessage();
}
}
public function removeChannel($channel) {
try {
$stmt = $this->connection->prepare("DELETE FROM config WHERE channel = :channel");
$stmt->bindParam(':channel', $channel);
$stmt->execute();
// flog('TERMINATING IRC CONNECTION');
flog("REMOVED CHANNEL ".$channel);
return "Channel removed successfully.";
} catch (PDOException $e) {
flog('REMOVE CHANNEL FAIL '.$e->getMessage());
return "Query failed: " . $e->getMessage();
}
}


public function getChannels() {
try {
$stmt = $this->connection->prepare("SELECT channel FROM config");
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $rows;
} catch (PDOException $e) {
echo "Query failed: " . $e->getMessage();
}
}

public function getConfig() {
try {
$stmt = $this->connection->prepare("SELECT channel FROM config");
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_OBJ);
return $rows;
} catch (PDOException $e) {
echo "Query failed: " . $e->getMessage();
}
}
}




$server = 'localhost';
$username = 'root';
$password = '@PASSword123';
$database = 'Twitch';
$db = new Database($server, $username, $password, $database);
$db->connect();
<?php
class Database {
private $server;
private $username;
private $password;
private $database;
private $connection;
public function __construct($server, $username, $password, $database) {
$this->server = $server;
$this->username = $username;
$this->password = $password;
$this->database = $database;
}
public function connect() {
$this->connection = new PDO("mysql:host=$this->server;dbname=$this->database", $this->username, $this->password);
$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
public function execute($sql){
try {
$stmt = $this->connection->prepare( $sql);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_OBJ);
return $rows;
} catch (PDOException $e) {
echo "Query failed: " . $e->getMessage();
}
}
public function getChannelsLogged() {
try {
$stmt = $this->connection->prepare("SELECT DISTINCT(channel) FROM history");
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row) {
echo $row['channel'] . "<br>";
}
} catch (PDOException $e) {
echo "Query failed: " . $e->getMessage();
}
}
public function getHistory($channel) {
try {
$stmt = $this->connection->prepare("SELECT * FROM history WHERE channel = :channel");
$stmt->bindParam(':channel', $channel);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row) {
echo "ID: " . $row['id'] . ", chatmsg: " . $row['chatmsg'] . "<br>";
}
} catch (PDOException $e) {
echo "Query failed: " . $e->getMessage();
}
}
public function getCount($channel) {
try {
$stmt = $this->connection->prepare("SELECT count(*) FROM history WHERE channel = :channel");
$stmt->bindParam(':channel', $channel);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row) {
echo "ID: " . $row['id'] . ", chatmsg: " . $row['chatmsg'] . "<br>";
}
} catch (PDOException $e) {
echo "Query failed: " . $e->getMessage();
}
}
public function getEntryCount() {
try {
$stmt = $this->connection->prepare("SELECT count(*) as total FROM history");
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_OBJ);
return $rows;
} catch (PDOException $e) {
echo "Query failed: " . $e->getMessage();
}
}
public function addChannel($channel) {
try {
$stmt = $this->connection->prepare("INSERT INTO config (channel) VALUES (:channel)");
$stmt->bindParam(':channel', $channel);
$stmt->execute();
flog('ADDED CHANNEL '.$channel);
return "Channel added successfully.";
} catch (PDOException $e) {
flog("ADD CHANNEL FAIL ". $e->getMessage());
return "Query failed: " . $e->getMessage();
}
}
public function addJoin($username, $channel) {
try {
$stmt = $this->connection->prepare("INSERT INTO visits (username,channel) VALUES (:username, :channel)");
$stmt->bindParam(':username', $username);
$stmt->bindParam(':channel', $channel);
$stmt->execute();
flog('ADDED JOIN '.$channel);
return "Channel added successfully.";
} catch (PDOException $e) {
flog("ADD CHANNEL FAIL ". $e->getMessage());
return "Query failed: " . $e->getMessage();
}
}
public function addChat($author, $channel,$message,$emotes) {
try {
$stmt = $this->connection->prepare("INSERT INTO history (author, channel, message, emotes) VALUES (:author,:channel,:message,:emotes)");
$stmt->bindParam(':author', $author);
$stmt->bindParam(':channel', $channel);
$stmt->bindParam(':message', $message);
$stmt->bindParam(':emotes', $emotes);
$stmt->execute();
return "added successfully.";
} catch (PDOException $e) {
flog("ADD CHAT FAIL ". $e->getMessage());
return "Query failed: " . $e->getMessage();
}
}
public function removeChannel($channel) {
try {
$stmt = $this->connection->prepare("DELETE FROM config WHERE channel = :channel");
$stmt->bindParam(':channel', $channel);
$stmt->execute();
// flog('TERMINATING IRC CONNECTION');
flog("REMOVED CHANNEL ".$channel);
return "Channel removed successfully.";
} catch (PDOException $e) {
flog('REMOVE CHANNEL FAIL '.$e->getMessage());
return "Query failed: " . $e->getMessage();
}
}
public function getChannels() {
try {
$stmt = $this->connection->prepare("SELECT channel FROM config");
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $rows;
} catch (PDOException $e) {
echo "Query failed: " . $e->getMessage();
}
}
public function getConfig() {
try {
$stmt = $this->connection->prepare("SELECT channel FROM config");
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_OBJ);
return $rows;
} catch (PDOException $e) {
echo "Query failed: " . $e->getMessage();
}
}
}
$server = 'db';
$username = 'root';
$password = '@PASSword123';
$database = 'Twitch';
$db = new Database($server, $username, $password, $database);
$db->connect();
?>
25 changes: 25 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: '3.1'

services:

db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
volumes:
- ./data:/docker-entrypoint-initdb.d
- ./db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: "@PASSword123"
ports:
- "3306:3306"

php:
image: team-twitch-chat-history
depends_on:
- db
ports:
- "8000:80"



13 changes: 13 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM php:7.4-apache

COPY . /var/www/html

RUN a2enmod rewrite

RUN apt-get update \
&& apt-get install -y --no-install-recommends libpq-dev \
&& docker-php-ext-install pdo_mysql

EXPOSE 80

CMD ["apache2-foreground"]
Loading