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

  

  

相关文章:

  • 2022-02-20
  • 2022-01-17
  • 2022-01-09
  • 2022-01-15
  • 2022-12-23
  • 2022-01-21
  • 2021-06-24
  • 2021-07-13
猜你喜欢
  • 2021-12-04
  • 2022-02-05
  • 2022-12-23
  • 2022-12-23
  • 2022-02-06
  • 2022-12-23
  • 2021-10-30
相关资源
相似解决方案