changed mysql package

This commit is contained in:
ishak jmilou.ishak
2024-12-12 14:00:26 +01:00
parent 5c4a0f1e9d
commit 820cb39781

View File

@@ -1,6 +1,6 @@
from flask import Flask, request, render_template, jsonify from flask import Flask, request, render_template, jsonify
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
from flask_mysqldb import MySQL import mysql.connector
app = Flask(__name__) app = Flask(__name__)
@@ -18,13 +18,15 @@ mqtt_client.loop_start()
mqtt_client.subscribe("kobuki/data") 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 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
app.config['MYSQL_HOST'] = 'localhost'
app.config["MYSQL_USER"] = 'admin'
app.config["MYSQL_PASSWORD"] = 'kobuki'
app.config["MYSQL_DB"] = 'kobuki'
mysql = MySQL(app) cnx = mysql.connector.connect(
host="127.0.0.1",
port=3306,
user="admin",
password="kobuki!",
database="kobuki")
cnx.close()
@app.route('/') @app.route('/')
def index(): def index():
@@ -62,7 +64,7 @@ def phpmyadmin_passthrough(path):
@app.route("/database") @app.route("/database")
def database(): def database():
try: try:
cur = mysql.connection.cursor() cur = cnx.cursor()
cur.execute("SELECT * FROM kobuki_data") cur.execute("SELECT * FROM kobuki_data")
rows = cur.fetchall() # Haal alle rijen op uit het resultaat rows = cur.fetchall() # Haal alle rijen op uit het resultaat
cur.close() cur.close()