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:
return '数据库语句执行成功'