Browse Source

Add v0.0.3 MariaDB connection test

main
def 2 weeks ago
parent
commit
ff56e247dd
  1. 2
      VERSION
  2. 37
      backend/app.py
  3. 8
      backend/config.py
  4. 11
      backend/db.py

2
VERSION

@ -1 +1 @@
0.0.2
0.0.3

37
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"""
<h1>Database Connection OK</h1>
<p>Server time: {result[0]}</p>
"""
except Exception as e:
return f"""
<h1>Database Connection FAILED</h1>
<pre>{e}</pre>
"""
if __name__ == "__main__":
app.run(host="127.0.0.1", port=5050)
app.run(host="0.0.0.0", port=5050)

8
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"

11
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
)
Loading…
Cancel
Save