You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
636 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

from pymysql import *
conn = connect(host='localhost', user='root', password='123456', database='tianqi', port=3306)
cursor = conn.cursor()
def query(sql, params, type='no_select'):
params = tuple(params)
cursor.execute(sql, params)
if type != 'no_select':
data_list = cursor.fetchall()
conn.commit()
return data_list
# type: 指定SQL 语句的类型,默认为'no_select'表示非查询语句如INSERT、UPDATE等。如果是查询语句可以传入其他值如 'select')。
else:
conn.commit()
return '数据库语句执行成功'