python 连接数据库条件查询2

from flask import Flask, request
import os
import json
import pymysql
os.environ[‘NLS_LANG‘] = ‘SIMPLIFIED CHINESE_CHINA.UTF8‘

app = Flask(__name__)
@app.route(‘/index1‘, methods=[‘POST‘])
def indextest():
    inputData = request.json.get(‘inputData‘)
    data1 = getcontent(inputData)
    return data1

def getcontent(inputData):
    conn = pymysql.connect(
        host="172.0.0.0", port=8888, user="test", password="pwd", database="table", charset="utf8")
    cur = conn.cursor()
    sql = "SELECT account,name,passwd FROM table where name=‘%s‘"%(inputData)
    cur.execute(sql)
    data = cur.fetchone()
    print(data)
    # para = []
    # for i in data:
    #     text = {‘account‘: i[0], ‘username‘: i[1], ‘password‘: i[2]}
    #     # print(text)
    #     para.append(text)

    result = {‘account‘: data[0], ‘username‘: data[1], ‘password‘: data[2]}
    return json.dumps(result, ensure_ascii=False, indent=4)


if __name__ == ‘__main__‘:
    app.run(host=‘127.0.0.4‘, port=5590)

  

通过输入参数,返回自己想要的结果

 

python 连接数据库条件查询2

 

python 连接数据库条件查询2

上一篇:javaweb视频第二天(三)(数据库)(我的数据库默认不是utf8)


下一篇:定时备份mysql数据(物理备份)