# Flask API 接口
@app.route('/api/user', methods=['GET'])
def get_user():
db = mysql.connector.connect(
host="localhost",
user="root",
database="demo_db"
)
cursor = db.cursor()
cursor.execute("SELECT * FROM users")
result = cursor.fetchall()
return jsonify(result)
@app.route('/api/order', methods=['GET'])
def get_order():
db = mysql.connector.connect(
host="localhost",
user="root",
database="demo_db"
)
cursor = db.cursor()
cursor.execute("SELECT * FROM orders")
result = cursor.fetchall()
return jsonify(result)