sql 语句使用和转换json数据


1 连接mysql

import pymysql
import concurrent
coon=pymysql.connect(host='localhost',user='root',password='123456',db='worlflow',charset='utf8',port=3306)
cursor=coon.cursor()
sql="insert into worker (worker_img) values('%s') where id=10"%str(encodesstr,'utf-8')
cursor.execute(sql)
coon.commit()
cursor.close()# 尽量关闭影响性能
coon.close() #

2  sql 语句查询 和转换json格式  

import pymysql
# Create your tests here.
def dictfetchall(cursor):
	desc=cursor.description
	# print(desc)
	return [
		dict(zip([col[0] for col in desc],row))
		for row in cursor.fetchall()
	]
def get_sql(sql):
	eng = pymysql.connect(host='localhost',user='root',password='1',db='loonviewdata',charset='utf8')
	cursor = eng.cursor()
	cursor.execute(sql)
	# data = cursor.fetchone()
	# data = cursor.fetchall()
	rsult=dictfetchall(cursor)
	return rsult

  

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM