Replace MariaDB connection with Flask-MySQLdb integration

This commit is contained in:
ishak jmilou.ishak
2024-12-09 14:59:42 +01:00
parent 9689d70104
commit 3bb40d5929

View File

@@ -1,6 +1,6 @@
from flask import Flask, request, render_template, jsonify
import paho.mqtt.client as mqtt
import mariadb
from flask_mysqldb import MySQL
app = Flask(__name__)
@@ -18,12 +18,12 @@ mqtt_client.loop_start()
mqtt_client.subscribe("kobuki/data")
mqtt_client.on_message = on_message # this lines needs to be under the function definition otherwise it cant find which function it needs to use
conn = mariadb.connect(
host='127.0.0.1',
user='admin',
password='kobuki',
database='kobuki')
cur = conn.cursor()
app.config['MYSQL_HOST'] = 'localhost'
app.config["MYSQL_USER"] = 'admin'
app.config["MYSQL_PASSWORD"] = 'kobuki'
app.config["MYSQL_DB"] = 'kobuki'
mysql = MySQL(app)
@app.route('/')
@@ -61,7 +61,8 @@ def phpmyadmin_passthrough(path):
@app.route("/database")
def database():
return "Connected to database"
cur = mysql.connection.cursor()
cur.execute("SELECT * FROM kobuki")
if __name__ == '__main__':
app.run(debug=True, port=5000)