1、首先,使用python查询mysql数据库代码如下:
import MySQLdb
def getcontent():
db = MySQLdb.connect('localhost', 'root', '1qaz!QAZ', 'zlnewschema', charset='utf8')
cursor = db.cursor()
sql = 'select * from user;'
cursor.execute(sql)
usercontent = cursor.fetchall()
print(usercontent)
for row in usercontent:
fname = row[0]
femail = row[1]
fpw = row[2]
ftime = row[3]
print('name=%s,email=%s,password=%s,createtime=%s' %(fname, femail, fpw,ftime))
db.close()
if __name__ == '__main__':
getcontent()
改为接口,用的Flask框架(可以对比看看需要改哪些地方):
Post请求(get直接换成get就行了):
import MySQLdb
import json
import os
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
from flask import Flask,request
# from flask_cors import *
app = Flask(__name__)
@app.route('/index1', methods=[