From ff56e247dd0fb0cd2fde3a6baf764a00ef5cd4b7 Mon Sep 17 00:00:00 2001 From: def Date: Sun, 8 Mar 2026 07:10:15 +0000 Subject: [PATCH] Add v0.0.3 MariaDB connection test --- VERSION | 2 +- backend/app.py | 37 +++++++++++++++++++++++++------------ backend/config.py | 8 ++++++++ backend/db.py | 11 +++++++++++ 4 files changed, 45 insertions(+), 13 deletions(-) create mode 100644 backend/config.py create mode 100644 backend/db.py diff --git a/VERSION b/VERSION index 4e379d2..bcab45a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.2 +0.0.3 diff --git a/backend/app.py b/backend/app.py index 46d049f..c168620 100644 --- a/backend/app.py +++ b/backend/app.py @@ -1,18 +1,31 @@ -from flask import Flask, render_template +from flask import Flask +from db import get_db_connection -app = Flask( - __name__, - template_folder="../templates", - static_folder="../static", -) +app = Flask(__name__) @app.route("/") def index(): - return render_template( - "base.html", - page_title="OTB Billing", - content="OTB Billing v0.0.1 is alive." - ) + return "OTB Billing v0.0.3 running" +@app.route("/dbtest") +def dbtest(): + try: + conn = get_db_connection() + cursor = conn.cursor() + cursor.execute("SELECT NOW()") + result = cursor.fetchone() + conn.close() + + return f""" +

Database Connection OK

+

Server time: {result[0]}

+ """ + + except Exception as e: + return f""" +

Database Connection FAILED

+
{e}
+ """ + if __name__ == "__main__": - app.run(host="127.0.0.1", port=5050) + app.run(host="0.0.0.0", port=5050) diff --git a/backend/config.py b/backend/config.py new file mode 100644 index 0000000..c6ff6ac --- /dev/null +++ b/backend/config.py @@ -0,0 +1,8 @@ +import os + +class Config: + DB_HOST = "127.0.0.1" + DB_PORT = 3306 + DB_NAME = "otb_billing" + DB_USER = "otb_billing" + DB_PASSWORD = "!2Eas678" diff --git a/backend/db.py b/backend/db.py new file mode 100644 index 0000000..a10f72b --- /dev/null +++ b/backend/db.py @@ -0,0 +1,11 @@ +import mysql.connector +from config import Config + +def get_db_connection(): + return mysql.connector.connect( + host=Config.DB_HOST, + port=Config.DB_PORT, + user=Config.DB_USER, + password=Config.DB_PASSWORD, + database=Config.DB_NAME + )