发布时间:2019-08-01 17:26:31编辑:auto阅读(1677)
import MySQLdb
import json
def getSql():
try:
con = MySQLdb.connect(host='localhost', user='', passwd='', db='test', charset='utf8')
cursor = con.cursor()
sql = "select * from user"
cursor.execute(sql)
results = cursor.fetchmany(5)
users = []
data = {}
for r in results:
user = {}
user['id'] = r[0]
user['name'] = r[1]
user['age'] = r[2]
user['tel'] = r[3]
user['address'] = r[4]
users.append(user)
data['code'] = 0
data['users'] = users
jsonStr = json.dumps(data)
cursor.close()
con.close()
return jsonStr
except MySQLdb.Error, e:
print "Mysql Error %d: %s" % (e.args[0], e.args[1])
上一篇: 【python图像处理】python绘制
下一篇: python读取ppt文本内容
47494
45794
36792
34323
28960
25597
24443
19611
19111
17632
5466°
6048°
5570°
5638°
6573°
5376°
5378°
5884°
5855°
7170°