import pymysql
from flask import Flask, request
from flask_cors import CORS
app = Flask(__name__)
CORS(app)
@app.route('/', methods=['GET'])
def hello():
args = request.args
wd = args.get("wd")
result = []
db = pymysql.connect(host='localhost',
user='root',
password='lylelove2000A',
database='jinghe')
cursor = db.cursor()
sql = "SELECT * FROM community WHERE work LIKE BINARY '%"+wd+"%'"
try:
cursor.execute(sql)
results = cursor.fetchall()
for row in results:
id = row[0]
name = row[1]
address = row[2]
work = row[3]
birthday = row[4]
workplace = row[5]
salary = row[6]
result.append({"id": id, "name": name})
except:
print("Error: unable to fetch data")
return result
if __name__ == '__main__':
app.run(debug=True)