python 查询mysql的时候以键值对方式查询
#!/usr/bin/python# -*- coding: UTF-8 -*-import MySQLdb as msddb = msd.connect("192.168.1.51", "xsy", "xsy123", "demo")# 使用cursor()方法获取操作游标cursorclass = msd.cursors.DictCursor 加人这个就是获取键值对cursor
·
转载来至
#!/usr/bin/python # -*- coding: UTF-8 -*- import MySQLdb as msd db = msd.connect("192.168.1.51", "xsy", "xsy123", "demo") # 使用cursor()方法获取操作游标 cursorclass = msd.cursors.DictCursor 加人这个就是获取键值对 cursor = db.cursor(cursorclass = msd.cursors.DictCursor) try: cursor.execute("SELECT * FROM edai_usersystab LIMIT 100") results=cursor.fetchall() for row in results: print "id=%s,numbers=%s,username=%s,pass=%s,usertype=%s" % \ (row['uid'], row['unumbers'], row['username'], row['userpass'], row['usertype'],) except: print "Error: unable to fecth data" # 关闭数据库连接 db.close()
更多推荐
已为社区贡献1条内容
所有评论(0)