mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-03 20:04:58 +00:00
Replace MariaDB connection with Flask-MySQLdb integration
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user