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.

32 lines
641 B

import pymysql
def connect_to_mysql():
return pymysql.connect(
host='localhost',
port=3306,
user='root',
password='root',
database='pythontest',
autocommit=True, # 自动提交
charset='utf8mb4'
)
def query_sql(sql):
conn = connect_to_mysql()
try:
cursor = conn.cursor()
cursor.execute(sql)
return cursor.fetchall()
finally:
conn.close()
def not_query_sql(sql):
conn = connect_to_mysql()
try:
cursor = conn.cursor()
cursor.execute(sql)
finally:
conn.close()